我需要对每个项目应用一个条件,如果为true,它应该在项目中显示复选框,如果为false,它应该隐藏。怎么做到这一点?
这是xaml:
$ username = $_GET ['Username'] $ user = $ users [$username] If ($ user == null){
// user not existent
} else {
// validate password
}
答案 0 :(得分:1)
尝试使用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>
答案 1 :(得分:0)
您可以使用DataTriggers
完成此操作。
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=PropertyThatSetsVisibility}" Value="True">
<Setter TargetName="NameOfCheckBoxToHideInItemTemplate" Property="Visibility" Value="Hidden"/>
</DataTrigger>
</DataTemplate.Triggers>