我想將UserControl中的元素的屬性綁定到Silverlight中UserControl本身上設置的屬性。我相信它應該很簡單,但我還沒有設法使用RelativeSource或ElementName綁定。在這個例子中,我想讓矩形爲綠色(或任何UserControl的背景屬性設置爲)。綁定到Silverlight中的父元素的屬性
<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>
有人知道正確的綁定語法嗎?