2010-09-01 74 views
0

后空我有一个用户控制,具有框架作为一个依赖属性依赖属性是价值分配

public partial class NavigationBar : UserControl 
{ 
    public NavigationBar() 
    { 
     this.InitializeComponent(); 
    } 

    public Frame NavigationFrame 
    { 
     get { return (Frame)GetValue(NavigationFrameProperty); } 
     set { SetValue(NavigationFrameProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for NavigationFrame. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty NavigationFrameProperty = 
     DependencyProperty.Register("NavigationFrame", typeof(Frame), typeof(NavigationBar), new UIPropertyMetadata()); 
} 

使用用户控件代码:

<userControls:NavigationBar NavigationFrame="{Binding ElementName=masterPage, Path=frameNavigations}" /> 

<Frame x:Name="frameNavigations"/> 

为什么NavigationFrame依赖加载后属性仍为null?

在此先感谢

回答

2

这将寻找与母版的名称你的页面的元素,然后找上对象调用frameNavigations的属性。我想你实际上是想绑定到名为frameNavigations的元素,所以你只需要写下:

<userControls:NavigationBar 
    NavigationFrame="{Binding ElementName=frameNavigations}"/> 
<Frame x:Name="frameNavigations"/>