1. Foreword
## In daily life In interface development, we mostly use the MVVM model for development. Normally, the ItemsSource of a PropertyGridControl or DataGrid is set up,
and then each column is bound to a field in an ItemsSource and then it can run .
But there is another situation:
## Assume an interface Temp.xaml, Its ViewModel is TempViewModel.cs;
There is a PropertyGridControl ItemsSource bound to ObservableCollection
JloprtyGridControl, a PropertyDefinition in the TEMPLATE, which is bound to be rewritten. # It may also It may include several fields in the Model, or even Some other information in the TempViewModel. How should I operate at this time?
2. Example
Temp.xaml:
<services:DockablePane.Resources> <ResourceDictionary> <DataTemplate x:Key="EditTemplate"> <special:SpEdit x:Name="PART_Editor"/> //这里是关键!!!!!!!!!!!!!!! </DataTemplate> </ResourceDictionary> </services:DockablePane.Resources> <dxprg:PropertyGridControl Margin="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"SelectedObjects="{Binding Infos}" ShowProperties="WithPropertyDefinitions"ShowDescriptionIn="ToolTipAndPanel" ShowCategories="True" ExpandCategoriesWhenSelectedObjectChanged="True"ShowMenuButtonInRows="False" ShowToolPanel="False" ShowSearchBox="False" SortMode="Definitions"> <dxprg:PropertyGridControl.PropertyDefinitions> <!--通用--> <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 name of the form in the DataTemplate we override is :
This name is very important and cannot be changed. In this way we can call all the information of TempViewModel
in the formSpEdit, because at this time TempViewModel
On aattribute that has been assigned to the DataContext of SpEdit, the possible situation is as follows: SpEdit.xaml.cs:
var source = this.DataContext as RowData;if (source != null) _sourceData = (source.Definition.DataContext) as VM;
##3. Summary
# # This article mainly describes how to obtain the ViewModel information in the source UI in the rewrite interface. PART_Editor is a very practical hidden method.
The above is the detailed content of Share usage examples of PART_Editor. For more information, please follow other related articles on the PHP Chinese website!