[MVVM Dev] use of PART_Editor, mvvmpart_editor
I. Preface
In daily interface development, we mostly use the MVVM mode for development. Generally, a PropertyGridControl or the ItemsSource of the DataGrid is set,
Then, each column is bound to a field in an ItemsSource to run.
However, there is another situation:
Assume that the ViewModel of Temp. xaml is TempViewModel. cs;
There is a PropertyGridControl ItemsSource bound to ObservableCollection <Model>;
In PropertyGridControl, A PropertyDefinition must overwrite the Template. The information it binds is not only a field in the Model,
It may also contain several fields in the Model, or some other information in the TempViewModel. How can this problem be solved?
Ii. Instances
Temp. xaml:
<Services: DockablePane. resources> <ResourceDictionary> <DataTemplate x: Key = "EditTemplate"> <special: SpEdit x: name = "PART_Editor"/> // here is the key !!!!!!!!!!!!!!! </DataTemplate> </ResourceDictionary> </services: DockablePane. resources> <dxprg: propertyGridControl Margin = "0" Highlight = "Stretch" Highlight = "Stretch" SelectedObjects = "{Binding Infos}" ShowProperties = "yellow" ShowDescriptionIn = "ToolTipAndPanel" ShowCategories = "True" Yellow = "True" ShowMenuButtonInRows = "False" ShowToolPanel = "False" ShowSearchBox = "False" SortMode = "Definitions"> <dxprg: PropertyGridControl. PropertyDefinitions> <! -- General --> <dxprg: PropertyDefinition IsReadOnly = "True" Path = "Code"/> <dxprg: PropertyDefinition IsReadOnly = "True" Path = "AProperty"/> <dxprg: propertyDefinition Path = "BProperty"/> <dxprg: PropertyDefinition Path = "CProperty"/> <dxprg: PropertyDefinition Path = "DProperty"/> <dxprg: propertyDefinition Path = "EProperty" ContentTemplate = "{StaticResource EditTemplate}"/> </dxprg: PropertyGridControl. propertyDefinitions> </dxprg: PropertyGridControl>
Here, the form name in the rewritten DataTemplate is:PART_Editor
This name is especially important and cannot be changed.
In this way, we can call all the information of the TempViewModel in the form of SpEdit, because at this time the TempViewModel has been assigned to the DataContextA Property,
The possible situation is as follows:
SpEdit. xaml. cs:
var source = this.DataContext as RowData;if (source != null) _sourceData = (source.Definition.DataContext) as VM;
In this way, the ViewModel of Temp. xaml is passed to the _ sourceData of SpEdit.
Iii. Summary
This article describes how to obtain the ViewModel information in the source UI on the rewrite interface. PART_Editor is a very practical hidden method.