我有一个包含堆栈面板的列表视图。其中包含数据网格。
我希望用户点击一个复选框。 一些数据将崩溃。对于任何列表视图项(
)(其余数据将上升)将在代码exmpale中提供一些帮助:
附上我的一些XAML代码:
<Style x:Key="ShowHideStyle" TargetType="StackPanel" >
<Style.Setters>
<Setter Property="Visibility" Value="Collapsed" />
</Style.Setters>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="True">
<Condition.Binding>
<MultiBinding Converter="{StaticResource V_converter }">
<Binding Path="Type"></Binding>
<Binding Path="NodeID"></Binding>
<Binding Path="TLV"></Binding>
</MultiBinding>
</Condition.Binding>
</Condition>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>
<ListView x:Name="LV" ItemsSource= "{Binding Lggv}" SelectionChanged="dataGridData_SelectionChanged" ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate x:Name="DT" >
<StackPanel x:Name="LVSP" DataContextChanged="LVSP_DataContextChanged" SourceUpdated="LVSP_SourceUpdated" Style="{StaticResource ShowHideStyle}">
<Border BorderThickness="1" BorderBrush="Black" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="55"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="tbHeader" Text="{Binding Info }" AllowDrop="True" FontWeight="Bold" Grid.Column="2" Visibility="{Binding Visibility_Header}" >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Background">
<Setter.Value>
<!-- this is the default background-->
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFCEE6C6" Offset="0.008"/>
<GradientStop Color="#FF9ECF8C" Offset="0.987"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
</Border>
<Grid x:Name="GridData">
<Grid.Background>
<MultiBinding Converter="{StaticResource converter }">
<Binding Path="Type"></Binding>
<Binding Path="NodeID"></Binding>
<Binding Path="TLV"></Binding>
</MultiBinding>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"></ColumnDefinition>
<ColumnDefinition Width="55"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding DateTime}" ></TextBlock>
</Border>
<Border Grid.Column="1" BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding ComPort}"></TextBlock>
</Border>
<Border Grid.Column="2" BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding Data}" ></TextBlock>
</Border>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:1)
您应该为targettype ItemContainerStyle
设置ListViewItem
,而不是定位您的商品内容(StackPanel
)。
在参考资料部分,定义你的风格
<Style x:Key="ShowHideStyle" TargetType="ListViewItem">
...
</Style>
然后使用它
<ListView ItemContainerStyle="{StaticResource ShowHideStyle}" .../>
当然,我认为你的转换器/触发器实际上正在工作,你只是有正确隐藏整个列表条目的问题。
答案 1 :(得分:0)
将StackPanel放入Expander并将样式应用于后者。
<ListView x:Name="LV" ItemsSource= "{Binding Lggv}" SelectionChanged="dataGridData_SelectionChanged"
ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate x:Name="DT" >
<Expander Header="..." Style="{StaticResource ShowHideStyle}">
<StackPanel x:Name="LVSP" DataContextChanged="LVSP_DataContextChanged" SourceUpdated="LVSP_SourceUpdated">
<Border...></Border...>
<Grid...></Grid...>
</StackPanel>
</Expander>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您可以将Expander的IsExpanded属性设置为false / true,而不是将Visbility属性设置为Collapsed / Visible:
<Style x:Key="ShowHideStyle" TargetType="Expander" >
<Style.Setters>
<Setter Property="IsExpanded" Value="False" />
</Style.Setters>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="True">
<Condition.Binding>
<MultiBinding Converter="{StaticResource V_converter }">
<Binding Path="Type"></Binding>
<Binding Path="NodeID"></Binding>
<Binding Path="TLV"></Binding>
</MultiBinding>
</Condition.Binding>
</Condition>
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsExpanded" Value="True" />
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
</Style>