WPF设置对象隐藏、不可用
设置隐藏时,这里将控件分为两类,
1、普通的按钮、下拉框等,根据控件的Name进行查找,设置IsEnabled为false;
2、ListView中嵌套控件,直接将列隐藏,根据GridViewColumn的Name进行查找,将CellTemplate = new DataTemplate();
public static void SetAuhority(ContentControl contentControl) { var list = LocalSession.AuthorityList.Where(m => m.FunctionClass == "E" && m.Page.Trim() == contentControl.DependencyObjectType.Name).ToList(); foreach (var item in list) { if (item.Function.Trim().StartsWith("column")) { var obj = contentControl.FindName(item.Function.Trim()); if(obj==null) { continue; } GridViewColumn gridViewColumn = (obj as GridViewColumn); //gridViewColumn.ClearValue(GridViewColumn.CellTemplateProperty); gridViewColumn.CellTemplate = new DataTemplate(); } else { UIElement element = contentControl.FindName(item.Function.Trim()) as UIElement; if (element == null) { continue; } //element.Visibility = Visibility.Hidden; element.IsEnabled = false; } }