正如标题所说,我想将我的扩展器的 IsExpanded 属性绑定到 ItemsControl 的 Items.Count 属性,即扩展器的内容。我需要更多扩展器的这种绑定,所以样式或类似的东西会很好。我已经尝试了在这里或其他网站上找到的一些东西,但没有任何效果。
这是我的实际代码:
<Style x:Key="ExpanderStyleKey" TargetType="Expander">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content.Items.Count}" Value="0">
<Setter Property="IsExpanded" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
谢谢你的帮助!
编辑:
这是我的扩展器之一的代码:
<Expander Name="exp1"
Header="Expander1"
Style="{StaticResource ExpanderStyleKey}">
<ItemsControl Name="itcMain"
ItemsSource="{Binding Path=ListInCodeBehind, Mode=OneWay}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=ExampleProperty}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Expander>
例子,
<Expander>
<Expander.Style>
<Style TargetType="Expander">
<Setter Property="IsExpanded" Value="{Binding Content.Items.Count, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
</Style>
</Expander.Style>
<Expander.Content>
<ItemsControl>
<ItemsControl.Items>
<TextBlock Text="Item1"/>
<TextBlock Text="Item2"/>
<TextBlock Text="Item3"/>
</ItemsControl.Items>
</ItemsControl>
</Expander.Content>
</Expander>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句