[MVVM Dev] use of PART_Editor, mvvmpart_editor

Source: Internet
Author: User

[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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.