DependencyObject.AssociatedObject 始终为 null [英] DependencyObject.AssociatedObject is always null

查看:32
本文介绍了DependencyObject.AssociatedObject 始终为 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的可见性"(在这种情况下只是一个布尔值)属性为假,我正在尝试编写一个客户行为以将某些列宽设置为 0...我的问题是当我的 on changed 事件触发它时我的 AssociatedObject 始终为空.

I am trying to write a customer behavior to set some column widths to 0 if my "Visibility" (which is just a bool in this case) property is false... My problem is that when my on changed event fires it my AssociatedObject is always null.

这里是相关的示例代码,有人可以看到我哪里出错了.

Here is the relevant sample code, mybe someone can see where I am going wrong.

  public static readonly DependencyProperty VisibilityProperty =
        DependencyProperty.Register("Visibility", typeof(bool), typeof(HideRadGridViewColumnBehavior), 
        new PropertyMetadata(OnVisibilityPropertyChanged));

private static void OnVisibilityPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
{
  if (((HideRadGridViewColumnBehavior)target).AssociatedObject == null)
    MessageBox.Show("AssociatedObject is null");
}

感谢您的帮助...

推荐答案

您如何附加行为?你能展示一些行为的代码吗?

how are you attaching the behavior? and can you show some code of the behavior?

在调用 附加或通过在

the AssociatedObject is set either after the call to Attach or through listing the behavior within <i:Interaction.Behaviors></i:Interaction.Behaviors>

这篇关于DependencyObject.AssociatedObject 始终为 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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