【发布时间】:2010-12-11 15:02:55
【问题描述】:
我正在尝试将 UserControl 中元素的属性绑定到 Silverlight 中 UserControl 本身的属性集。我确信它应该很简单,但我还没有设法让它与 RelativeSource 或 ElementName 绑定一起工作。在此示例中,我希望 Rectangle 为绿色(或任何 UserControl 的 Background 属性设置为)。
<UserControl x:Class="MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="40" Height="40" Background="Green" x:Name="root">
<Grid x:Name="LayoutRoot" Background="White">
<Rectangle x:Name="indicatorRectangle" Fill="{Binding Path=Background, ElementName=root}" Margin="0,0,26,0" />
</Grid>
</UserControl>
有人知道正确的绑定语法吗?
【问题讨论】:
标签: silverlight data-binding user-controls