c# - 依赖属性 null

标签 c# xaml uwp

我已经使用 Owner 属性创建了我的 UserControl

<shared:NavigationControl Owner="{Binding  ElementName=This, Converter={StaticResource TestConverter}}"  />

属性是我页面的x:Name

下面是代码:

public MvxWindowsPage Owner
{
    get { return (MvxWindowsPage)GetValue(OwnerProperty); }
    set { SetValue(OwnerProperty, value); }
}

public static readonly DependencyProperty OwnerProperty =
              DependencyProperty.Register("Owner", typeof(MvxWindowsPage), typeof(NavigationControl), null);

我创建了 TestConverter 来检查绑定(bind)是否正常。

为什么 Owner 属性在 cs 中为 null

最佳答案

问题很可能出在您的 This 属性中。您必须确认它不为空。添加一个 PropertyChanged 回调,然后调试并确认发送到您的 OwnerProperty 的值不为空。

public MvxWindowsPage Owner
{
    get { return (MvxWindowsPage)GetValue(OwnerProperty); }
    set { SetValue(OwnerProperty, value); }
}

public static readonly DependencyProperty OwnerProperty =
              DependencyProperty.Register("Owner", typeof(MvxWindowsPage), typeof(NavigationControl), new PropertyMetadata(PropChanged));

public static void PropChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
      var value = e.NewValue; //confirm this isn't null
}

关于c# - 依赖属性 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42399485/

相关文章:

c# - B-Trees/B+Trees 和重复键

c# - 如何在中间是其他窗口的占位符的 WPF 中创建布局?

c# - 如何从 MenuItem 完全自定义弹出窗口?

xml - StandardStyles 中的 "&#xE100"值

c# - 有没有办法在代码隐藏中解析 UWP 中的矢量路径几何?

c# - Xamarin.Forms 在文件系统中保存文件

uwp - 在 UWP 中使用 System.Reflection.Emit 动态创建一个类

c# - 使用 TempFileCollection 删除 ASP.NET MVC C# 中的临时文件

c# - 如何使用 Win32API 在其他进程中滚动窗口

c# - 列表框中的项目溢出