public static readonly DependencyProperty SingleGridLengthProperty = DependencyProperty.Register("SingleGridLength", typeof(double), typeof(MapConverter));
public class MapConverter : DependencyObject, INotifyPropertyChanged, IMultiValueConverter
{
public double SingleGridLength
{
get { return (double)GetValue(MapConverter.SingleGridLengthProperty); }
set
{
SetValue(MapConverter.SingleGridLengthProperty, value);
OnNotifyPropertyChanged("SingleGridLength");
}
}
<local:MapConverter x:Key="MapConverter"
SingleGridLength="{Binding SingleGridLength, RelativeSource={RelativeSource Self}}" />
我有一个转换器,它在 .xaml 中绑定(bind)了一组依赖属性
我遇到的问题是每个属性都在“获取”并返回值,但它从未“设置”该值。我可以在转换器中使用依赖属性吗?或者我应该以不同的方式处理这个问题?提前致谢!
最佳答案
首先,您的绑定(bind)无效。您正在将 SingleGridLength 属性绑定(bind)到其自身。您需要将其绑定(bind)到另一个属性/对象。
其次,您不应在 SingleGridLength 属性的 setter 中引发 OnNotifyPropertyChanged。您只需对常规 CLR 属性执行此操作。依赖属性有一个内置的更改通知系统,绑定(bind) Hook 到其中。
关于wpf - 依赖属性 : Getting but not Setting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6031320/