Wpf绑定路径的性能影响= {x:静态< propertypath>}? [英] Performance impact of Wpf Binding Path={x:Static <propertypath>}?

查看:209
本文介绍了Wpf绑定路径的性能影响= {x:静态< propertypath>}?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CLR实例属性,一个指向实例属性的静态PropertyPath和一个直接使用静态PropertyPath的xaml绑定:



NB:GetPropertyPath只是一种基于成员名称中给定的linq表达式返回属性路径的方法。

  

public static PropertyPath MyPropertyPath = GetPropertyPath(p => p.MyProperty);

私有对象_myProperty;

public object MyProperty
{
get {return _myProperty;}
set
{
_myProperty = value;
OnPropertyChanged(MyPropertyPath.Path);
}
}


然后使用MyViewModel作为标准mvvm时尚的数据标签,xaml绑定如下:

  
{Binding Path = {x:Static myNamespace:MyViewModel.MyPropertyPath}}

这种方法有很大的好处,因为代码不使用任何引用不作为构建的一部分进行检查。如果视图模型代码中的某些内容发生变化,那么构建的xaml绑定错误如果它们不再正确。



我的问题是这个,任何人都知道任何负面的性能会影响这个方法可能有吗?

解决方案

我认为GetPropertyPath()的影响在这里是相当可忽略的,因为我把结果一个静态变量,而不是直接使用
'OnPropertyChanged(Expression> expression)所需的重复调用。



然而,在数据绑定的内部方面我有点模糊,会直接向xaml提供x:Static属性路径,以提供任何性能改进?我使用x:static降级性能吗?


I have a CLR instance property, a static PropertyPath which points to the instance property and a xaml binding which uses the static PropertyPath directly like so:

NB: GetPropertyPath is simply a method which returns the propertypath based on the given linq expression from the member name.



    public static PropertyPath MyPropertyPath = GetPropertyPath(p=> p.MyProperty);

    private object _myProperty;

    public object MyProperty
    {
       get{ return _myProperty;}
       set 
       {
         _myProperty = value;
         OnPropertyChanged(MyPropertyPath.Path);
      }
    }


Then with MyViewModel as the datacontext in standard mvvm fashion the xaml binding is given as:

 
    {Binding Path={x:Static myNamespace:MyViewModel.MyPropertyPath}}

This approach has major benefit as the code does not use any references which are not checked as part of the build. If something is changed in the viewmodel code the xaml bindings error at build if they are no longer correct.

My question is this, is anyone aware of any negative performance impacts this approach could possibly have?

解决方案

I think the impact of GetPropertyPath() would be fairly negligable here as I am holding the result in a static variable rather than calling repeatedly as would be required for using 'OnPropertyChanged(Expression> expression)' directly.

I am however a little fuzzy on the internals of databinding, would providing the x:Static propertypath directly to the xaml provide any performance improvement? Am I degrading performance by using x:static?

这篇关于Wpf绑定路径的性能影响= {x:静态< propertypath>}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆