我将网格RowDetailsVisibilityMode设置为Collapsed并使用带有样式化Togglebutton的DataGrIDTemplateColumn来切换行可见性.
可以使用绑定或TriggerAction连接切换按钮以切换行可见性.
绑定必须在代码隐藏中完成,因为您尝试将Togglebutton.IsChecked绑定到生成的元素并且在XAML中不存在(DataGrIDRow.DetailsVisibility)
(SL5中允许使用更强的relativeSource绑定)
对于这两种解决方案,我在辅助类中都有这个扩展方法:
/// <summary> /// Walk up the VisualTree,returning first parent object of the type supplIEd as type parameter /// </summary> public static T FindAncestor<T>(this DependencyObject obj) where T : DependencyObject { while (obj != null) { T o = obj as T; if (o != null) return o; obj = VisualTreeHelper.GetParent(obj); } return null; }
对于代码隐藏绑定方法:
private voID Togglebutton_Loaded(object sender,RoutedEventArgs e) { Togglebutton button = sender as Togglebutton; DataGrIDRow row = button.FindAncestor<DataGrIDRow>(); //Custom Extension row.SetBinding(DataGrIDRow.DetailsVisibilityProperty,new Binding() { Source = button,Path = new PropertyPath("IsChecked"),Converter = new VisibilityConverter(),Mode = BindingMode.TwoWay }); }
对于TriggerAction方法:
public class ExpandRowAction : TriggerAction<Togglebutton>{ protected overrIDe voID Invoke(object o) { var row = this.Associatedobject.FindAncestor<DataGrIDRow>(); if (row != null) { if (this.Associatedobject.IsChecked == true) row.DetailsVisibility = Visibility.Visible; else row.DetailsVisibility = Visibility.Collapsed; } }}
然后在XAML中:
<sdk:DataGrIDTemplateColumn.CellTemplate> <DataTemplate> <Togglebutton Style="{StaticResource PlusMinusTogglebuttonStyle}" > <i:Interaction.Triggers> <i:EventTrigger Eventname="Click"> <behaviors:ExpandRowAction/> </i:EventTrigger> </i:Interaction.Triggers> </Togglebutton> </DataTemplate></sdk:DataGrIDTemplateColumn.CellTemplate>总结
以上是内存溢出为你收集整理的在Silverlight DataGrid中展开/折叠按钮全部内容,希望文章能够帮你解决在Silverlight DataGrid中展开/折叠按钮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)