【发布时间】:2012-12-09 17:19:27
【问题描述】:
WindowsPhoneControl1.xaml.cs:
public partial class WindowsPhoneControl1
{
public static readonly DependencyProperty MyDpProperty =
DependencyProperty.Register("MyDp",
typeof (Color),
typeof (WindowsPhoneControl1),
new PropertyMetadata(default(Color)));
public Color MyDp
{
get { return (Color) this.GetValue(MyDpProperty); }
set { this.SetValue(MyDpProperty, value); }
}
...
}
WindowsPhoneControl1.xaml:
<UserControl x:Class="MyProj.WindowsPhoneControl1" x:Name="Uc" ...>
<Rectangle Width="200" Height="200" Fill="{Binding MyDp, ElementName=Uc}" />
<!--<Rectangle Width="200" Height="200" Fill="Red" /> Works fine-->
</UserControl>
MainPage.xaml:
<Grid x:Name="LayoutRoot">
<myProj:WindowsPhoneControl1 MyDp="SandyBrown" />
</Grid>
那么为什么{Binding MyDp, ElementName=Uc} 不起作用,在这种情况下该怎么办?
【问题讨论】:
标签: c# silverlight windows-phone-7 xaml dependency-properties