代码之家  ›  专栏  ›  技术社区  ›  IgorMF

WpfToolkit属性网格

  •  0
  • IgorMF  · 技术社区  · 7 年前

    PreparePropertyItem PropertyGrid Extended WPF Toolkit™ by Xceed 以MVVM友好的方式:

    <UserControl x:Class=(...)
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:mvvm="http://prismlibrary.com/" 
    (...)
    <xctk:PropertyGrid x:Name="PropertyGrid" SelectedObject="{Binding}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="PreparePropertyItem">
                <mvvm:InvokeCommandAction Command="{Binding PreparePropertyCommand}"/> //PRISM's InvokeCommandAction doesn't work
                <i:InvokeCommandAction Command="{Binding PreparePropertyCommand}"/> //BLEND's InvokeCommandAction doesn't work either
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </xctk:PropertyGrid>
    

    当加载或显示propertygrid时,不会调用我的自定义PreparePropertyCommand,只有当我单击以展开 [ExpandableObject]

    <xctk:PropertyGrid x:Name="PropertyGrid" SelectedObject="{Binding}" PreparePropertyItem="PropertyGrid_PreparePropertyItem">
    

    当然,这打破了MVVM模型 PropertyGrid_PreparePropertyItem 在视图的代码后面继续。

    有什么见解吗?谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   mm8    7 年前

    http://joyfulwpf.blogspot.se/2009/05/mvvm-invoking-command-on-attached-event.html

    当然,这打破了MVVM模型,因为PropertyGrid\u PreparePropertyItem在视图的代码后面。

    private void PropertyGrid_PreparePropertyItem(object sender, Xceed.Wpf.Toolkit.PropertyGrid.PropertyItemEventArgs e)
    {
        YourViewModel vm = PropertyGrid.DataContext as YourViewModel;
        if (vm != null)
            vm.PreparePropertyCommand.Execute(null);
    }
    

    MVVM不是关于消除 与视图相关