5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WPFのListViewコントロールのヘッダーを固定サイズで使用する

Posted at

ヘッダーのカラムをドラッグで入れ替えできないように抑制する用法

ヘッダーカラムの入れ替えを抑制するには、GridViewColumnHeaderタグを明示的に記述して、IsEnabledプロパティをFalseに設定します。

Test.xaml
<ListView>
  <ListView.View>
    <GridView>
      <GridViewColumn>
        <GridViewColumnHeader IsEnabled="False"/> <!-- 入れ替えの抑制 -->
      </GridViewColumn>
    </GridView>
    </ListView.View>
  </ListView>
</Grid>

ヘッダーのカラムのリサイズを抑制する方法

ヘッダーカラムのリサイズを抑制するには、GridViewColumnHeaderのStyleを利用します。Blendで、GridViewColumnHeaderのスタイルをコピーして、PART_HeaderGripperという名前の付いたThumbクラスを探し出します。PART_HeaderGripperがカラムのセパレーターで、GridViewColumnHeaderGripperスタイルを変更すれば、縦棒の色を変えることもできます。リサイズを抑制したい場合には、IsEnabledプロパティをFalseに設定します。

Test.xaml
<Style x:Key="{x:Type GridViewColumnHeader}" TargetType="{x:Type GridViewColumnHeader}">
  <!-- 中略 -->
  <Canvas>
    <Thumb x:Name="PART_HeaderGripper"
      Width="Auto"
      Margin="0,0,7,0"
      HorizontalAlignment="Stretch"
      IsEnabled="False"
      Style="{StaticResource GridViewColumnHeaderGripper}" />
  </Canvas>
  <!-- 中略 -->
</Style>
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?