脚本宝典收集整理的这篇文章主要介绍了分享PART_Editor的使用实例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。一、前言
在日常的界面开发中,我们大多使用MVVM模式进行开发。通常情况下,一个PRoPErtyGrIDControl或者DataGrid的ITemsSource设置好,
然后每一列绑定好某一条ItemsSource中的某一个字段就可以跑起来了。
但是也有另一种情况:
假设一个界面Temp.xaml,它的ViewModel为TempviewModel.cs;
有一个PropertyGridControl的ItemsSource以ObservableCollection<model>绑定;
PropertyGridControl中的一个PropertyDefinition要重写Template,它所绑定的信息并不只有Model中的某个字段,
还可能包括Model中的若干个字段,甚至TempViewModel中的一些其它信息,这个时候该如何操作?
二、实例
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>
在这里,我们重写的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;
这样,我们就把Temp.xaml的ViewModel传给了SpEdit的_sourceData。
三、小结
本文主要描述了如何在重写界面中获取源UI中的ViewModel信息。PART_Editor是一个非常实用的隐藏方法。
以上就是分享PART_Editor的使用实例的详细内容,更多请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的分享PART_Editor的使用实例全部内容,希望文章能够帮你解决分享PART_Editor的使用实例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。