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; } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步