这篇文章将为大家详细讲解有关PART_Editor的使用实例,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
<强>一、前言强>
<强>,,,强>在日常的界面开发中,我们大多使用MVVM模式进行开发。通常情况下,一个PropertyGridControl或者DataGrid的ItemsSource设置好,
,,,然后每一列绑定好某一条ItemsSource中的某一个字段就可以跑起来了。
,,,但是也有另一种情况:
,,,,,,假设一个界面Temp.xaml,它的视图模型为TempViewModel.cs;
,,,有一个PropertyGridControl的ItemsSource以ObservableCollection
,,,PropertyGridControl中的一个PropertyDefinition要重写模板,它所绑定的信息并不只中有模型的某个字段,
,,,还可能包括模型中的若干个字段,甚至TempViewModel中的一些其它信息,这个时候该如何操作?
<强>二、实例强>
温度。xaml:
,& lt;服务:DockablePane.Resources> ,,,,,,,& lt; ResourceDictionary> ,,,,,,,,,,,,& lt; DataTemplate x:关键=癊ditTemplate"比; ,,,,,,,,,,,,,,,& lt;特殊:SpEdit x: Name=癙ART_Editor"/祝辞,,//这里是关键! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ,,,,,,,,,,,& lt;/DataTemplate> ,,,,,,,& lt;/ResourceDictionary> ,& lt;/服务:DockablePane.Resources> & lt; dxprg: PropertyGridControl ,,,,,,,,,,,,,,,利润=?“,VerticalAlignment=癝tretch", HorizontalAlignment=癝tretch" SelectedObjects=皗} Binding 信息“,ShowProperties=癢ithPropertyDefinitions" ShowDescriptionIn=癟oolTipAndPanel", ShowCategories=癟rue", ExpandCategoriesWhenSelectedObjectChanged=癟rue" ShowMenuButtonInRows=癋alse", ShowToolPanel=癋alse", ShowSearchBox=癋alse", SortMode=癉efinitions"比; ,& lt; dxprg: PropertyGridControl.PropertyDefinitions> ,,,,,,,,,,,,,,,,,,,,,,,& lt; !——通用——比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition IsReadOnly=癟rue",路径=癈ode"/比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition IsReadOnly=癟rue",路径=癆Property"/比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition 路径=癇Property"/比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition 路径=癈Property"/比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition 路径=癉Property"/比; ,,,,,,,,,,,,,,,,,,,,,,,& lt; dxprg: PropertyDefinition 路径=癊Property",, ContentTemplate=皗StaticResource EditTemplate},/比; ,& lt;/dxprg: PropertyGridControl.PropertyDefinitions> & lt;/dxprg: PropertyGridControl>
在这里,我们重写的DataTemplate中的窗体名称为:<强> PART_Editor 强>
这个名字特别重要,不能改其它的。
这样我们就可以在SpEdit这个窗体中调用TempViewModel的全部信息,因为这个时候TempViewModel已经赋值给了SpEdit的DataContext的<强>某个属性>强上,
可能的情况是这样的:
SpEdit.xaml。cs:
var source =, this.DataContext as RowData; if (source !=, null) ,,,,_sourceData =, (source.Definition.DataContext), as VM;
这样,我们就把临时。xaml的ViewModel传给了SpEdit的_sourceData。
关于“PART_Editor的使用实例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看的到。