Dependency property in User Control is null after assigning value
I have a user control, has a Frame as a dependency property
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());
}
Using the User Control code:
<userControls:NavigationBar NavigationFrame="{Binding ElementName=masterPage, Path=开发者_运维知识库frameNavigations}" />
<Frame x:Name="frameNavigations"/>
Why the NavigationFrame dependency property still null after loading ?
Thanks in advance
That will look for an element in your page with a name of masterPage, and then look for a property on that object called frameNavigations. I think you actually want to bind to the element with the name frameNavigations, so you would just write:
<userControls:NavigationBar
NavigationFrame="{Binding ElementName=frameNavigations}"/>
<Frame x:Name="frameNavigations"/>
精彩评论