gpt4 book ai didi

c# - 如何从列表框中的项目访问复选框

转载 作者:太空宇宙 更新时间:2023-11-03 13:08:48 26 4
gpt4 key购买 nike

我需要对每个项目应用一个条件,如果为真,它应该在项目中显示复选框,如果为假,它应该隐藏。如何实现?

这是 xaml:

                    <ListBox Name="lbAllInstances" Width="500" Height="400"
SelectionMode="Multiple"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectionChanged="lbAllInstances_SelectionChanged">

<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="6" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" VerticalAlignment="Center" />
<TextBlock Grid.Column="2" Text="{Binding Name}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>

</ListBox>

最佳答案

尝试使用 BooleanToVisibilityConverter

<!-- In your resources section of the XAML -->
<BooleanToVisibilityConverter x:Key="BoolToVis" />

<ListBox.ItemTemplate>
...
<CheckBox Grid.Column="0" VerticalAlignment="Center"
Visibility="{Binding Path=IsVisibleProperty, Converter={StaticResource BoolToVis}}"/>
...
</ListBox.ItemTemplate>

关于c# - 如何从列表框中的项目访问复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29894953/

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