gpt4 book ai didi

wpf - ListView.GridViewColumn 对齐中的控制

转载 作者:行者123 更新时间:2023-12-03 02:25:29 25 4
gpt4 key购买 nike

我有以下 WPF ListView:

    <ListView Grid.Column="2" Grid.Row="1" Margin="0,53,12,6" 
Name="lvwProperties"
ItemsSource="{Binding Path=SelectedPropertyItems, Mode=TwoWay}"
Grid.ColumnSpan="2">

<ListView.View >

<GridView>
<GridViewColumn Header="Property" DisplayMemberBinding="{Binding Path=PropertyName, Mode=TwoWay}" Width="130" />
<GridViewColumn Header="Is Mandatory" Width="90" >

<GridViewColumn.CellTemplate>

<DataTemplate>

<CheckBox IsChecked="{Binding Path=IsMandatory, Mode=TwoWay}" HorizontalAlignment="Center" />

</DataTemplate>

</GridViewColumn.CellTemplate>

</GridViewColumn>

</GridView>
</ListView.View>
</ListView>

我想让复选框在第二个 GridColumn 中居中对齐。设置 Horizo​​ntalAlignment="Center" 似乎并不能解决问题。如何在 XAML 中实现这一点???

最佳答案

要将 ListView 中的内容居中,您需要将 ListView.ItemContainerStyle 设置为 Stretch 水平对齐,如下所示:

<ListView Grid.Column="2" Grid.Row="1" Margin="0,53,12,6" Name="lvwProperties"  
ItemsSource="{Binding Path=SelectedPropertyItems, Mode=TwoWay}"
Grid.ColumnSpan="2">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Property" DisplayMemberBinding="{Binding Path=PropertyName, Mode=TwoWay}" Width="130" />
<GridViewColumn Header="Is Mandatory" Width="90" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsMandatory, Mode=TwoWay}" HorizontalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>

关于wpf - ListView.GridViewColumn 对齐中的控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3842168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com