正如标题所说,我想将我的Expander的属性IsExpanded绑定到ItemsControl的Items.Count属性,这是Expander的内容。我需要这个绑定更多的扩展器,所以风格或类似的东西会很好。我已经尝试过在这里或其他网站上找到的东西,但没有任何效果。
这是我的实际代码:
<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之一的代码:
<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>
答案 0 :(得分:0)
实施例,
<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>