首页后端开发ASP.NET分享PART

分享PART

时间2024-01-30 12:03:03发布访客分类ASP.NET浏览318
导读:收集整理的这篇文章主要介绍了分享PART_Editor的使用实例,觉得挺不错的,现在分享给大家,也给大家做个参考。一、前言 在日常的界面开发中,我们大多使用MVVM模式进行开发。通常情况下,一个PRoPErtyGrIDContro...
收集整理的这篇文章主要介绍了分享PART_Editor的使用实例,觉得挺不错的,现在分享给大家,也给大家做个参考。一、前言

在日常的界面开发中,我们大多使用MVVM模式进行开发。通常情况下,一个PRoPErtyGrIDControl或者DataGrid的ITemsSource设置好,

然后每一列绑定好某一条ItemsSource中的某一个字段就可以跑起来了。

但是也有另一种情况:

假设一个界面Temp.xaml,它的ViewModel为TempviewModel.cs;

有一个PropertyGridControl的ItemsSource以ObservableCollectionmodel> 绑定;

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的使用实例的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

MVVM使用"

若转载请注明出处: 分享PART
本文地址: https://pptw.com/jishu/592495.html
System.Object是什么?如何使用System.Object? javascript中怎么找父标签

游客 回复需填写必要信息