/// <summary> /// 注册扩展 /// </summary> /// <typeparam name="TEditor">扩展类型</typeparam> /// <typeparam name="TConfig">对应的类型</typeparam> /// <param name="name">扩展名称</param> /// <param name="index">显示顺序</param> /// <param name="filter">关联的工作模式</param> public static void Registe <TConfig, TEditor>(string name, int index, params string[] filter) where TEditor : UserControl, new() where TConfig : ConfigBase { if (!ExtendDictionary.TryGetValue(typeof(TConfig), out var exts)) { ExtendDictionary.Add(typeof(TConfig), exts = new Dictionary <string, ExtendViewOption>(StringComparer.OrdinalIgnoreCase)); } if (exts.ContainsKey(name)) { exts[name] = new ExtendViewOption { Index = index, Name = name, Caption = name, Create = () => new TEditor() } } ; else { exts.Add(name, new ExtendViewOption { Index = index, Name = name, Caption = name, Create = () => new TEditor() }); } if (filter.Length > 0) { exts[name].Filter.AddRange(filter.Select(p => p.ToLower())); } }
private void CreateExtendEditor(string title, ExtendViewOption option) { var editor = option.Create(); var vm = (ExtendViewModelBase)editor.DataContext; vm.BaseModel = Model; var item = new TabItem { Header = title, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch }; var ext = new ExtendPanel { Child = editor, DataContext = editor.DataContext, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, }; item.Content = ext; ExtendEditorPanel.Items.Add(item); item.UpdateLayout(); }