WPF Expander问题
wpf吧
全部回复
仅看楼主
level 1
Faith_涛 楼主
在一个LixtBox中有多个Expander怎么实现在同一时间只能打开一个Expander,就是当展开一个Expander时,之前展开的会自动关闭
2015年03月06日 03点03分 1
level 11
两种方法。一种是当某个Expander展开时,用代码搜索其它Expander把IsExpanded设为false。可以把这个功能添加到某个属性中(GroupName之类)
第二种,偷懒的办法。用Expander代替RadioButton的默认模板,并把IsExpanded绑定到IsChecked属性。这样同一个组中只能有一个Expander(实际上是RadioButton)展开,无需代码。
2015年03月06日 06点03分 2
listbox的itemsource是绑定的 前台没有直接写他的内容,还有就是如果用RadioButton那不是前面有个选择的圆圈了吗,跟Expander样式不一样了啊
2015年03月06日 09点03分
回复
Faith_��
:注意:是替换 【模板】!!!
2015年03月06日 12点03分
level 11
<ControlTemplate TargetType=“RadioButton”>
<Expander Content=“{TemplateBinding Content}” IsExpanded=“{ Binding RelativeSource={RelativeSource TemplateParent},Path=IsChecked}” ....../>
</ControlTemplate>
省略了其它属性的设置
2015年03月06日 13点03分 3
我直接在RadioButton的content下面放expander还是有那个圆圈,到底怎么去掉RadioButton 前面的圆圈啊
2015年03月19日 03点03分
level 5
1楼说的对,使用RadioButton 作为模板修改。
2015年03月10日 08点03分 4
我直接在RadioButton的content下面放expander还是有那个圆圈,到底怎么去掉RadioButton 前面的圆圈啊
2015年03月19日 03点03分
回复
Faith_��
:不能直接放在content下面,这相当于用Expander代替了RadioButton显示的文字,只能改模板。
2015年03月21日 06点03分
回复
Faith_��
:关于模板的具体用法可以看MSDN
2015年03月21日 06点03分
回复 诹奈大法好🍭 :你好,请问怎么把Expander的header加入到radiobutton中,我找了好久都没找到方法
2018年03月27日 11点03分
level 9
<Style x:Key="ExpandListItemStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border BorderThickness="1">
<Border CornerRadius="3" Padding="2,1,2,2" BorderThickness="1" BorderBrush="#FF666670">
<Expander Header="Header" Content="{TemplateBinding ContentControl.Content}" IsExpanded="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="GroupListBox" TargetType="{x:Type ListBox}">
<Setter Property="ListBox.SelectionMode" Value="Single" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ItemsControl.ItemContainerStyle" Value="{StaticResource ExpandListItemStyle}" />
</Style>
对listboxitem设置模板,在里面放expander,绑定其IsExpanded到IsChecked
2016年03月24日 13点03分 5
1