开发者

Lock a grid column in place when changing GridViewColumn width

开发者 https://www.devze.com 2023-02-13 20:09 出处:网络
I have a DataTemplate for a gridview column, it has 2 items in it, an image and a text block, I want to \"lock\" the image to the left side of the column, even if开发者_开发知识库 the user expand the

I have a DataTemplate for a gridview column, it has 2 items in it, an image and a text block, I want to "lock" the image to the left side of the column, even if开发者_开发知识库 the user expand the width of the column, I want the image to stay put.

any ideas ?


Try to set HorizontalContentAlignment to Stretch for GridViewColumnHeader

<ListView ...>
    <ListView.Resources>
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.Resources>
    <!--...-->
</ListView>

Then your HeaderTemplate can look something like this if you want the TextBlock to be centered. Otherwise just remove the HorizontalAlignment

<DataTemplate>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" .../>
        <TextBlock Grid.Column="1" HorizontalAlignment="Center" .../>
    </Grid>
</DataTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消