我有一个lvAccessPoints列表,它有3个属性, 1)名称 2)密码 3)isSecured
我在每个项目中都有一个texbox和按钮,我当前正在选择一个项目时显示。
所以现在当我选择一个项目文本框时,按钮就会出现。
但我还想查看属性isSecured以显示文本框
条件是
textbox=> visible: if item is selected and has isSecured property true
hidden:if isSecured is false (irrespective of selected or not)
<ListView Margin="0" Name="lvAccessPoints" Background="#ff1d1d1d" Grid.Row="1" BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<!--<iconPacks:PackIconModern Kind="ConnectionWifi" Foreground="White" Width="30" Height="30"/>-->
<TextBlock Text="{Binding Points.Name}" FontWeight="Bold" Foreground="White" Padding="10,0" FontSize="15" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
<TextBox HorizontalAlignment="Left"
x:Name="txt"
TextWrapping="Wrap"
Text="{Binding Password}"
VerticalAlignment="Center"
Width="200"
Height="28"
Visibility="Collapsed" />
<Button x:Name="btn" Grid.Column="1" Visibility="Collapsed" Width="100" Margin="10" HorizontalAlignment="Left" Background="#FF2d89ef" Foreground="White" Padding="5" VerticalAlignment="Center" Grid.Row="2" Click="Button_Click_1">
<TextBlock Text="Connect" />
</Button>
</StackPanel>
</WrapPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}}" Value="True">
<Setter TargetName="txt" Property="Visibility" Value="Visible" />
<Setter TargetName="btn" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListView.ItemTemplate>
要显示文本框,我需要检查2个属性,一个是isSecured,另一个是isSelectd。
如何更改我的代码?
答案 0 :(得分:1)
使用MultiDataTrigger
:
<DataTemplate.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}}" Value="True" />
<Condition Binding="{Binding Path=points.isSecured}" Value="True"/>
</MultiDataTrigger.Conditions>
<Setter TargetName="txt" Property="Visibility" Value="Visible" />
<Setter TargetName="btn" Property="Visibility" Value="Visible" />
</MultiDataTrigger>
</DataTemplate.Triggers>