2010-07-30 78 views

回答

1

您可以綁定到一個祖先控制,如:

<Button Background="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=Background}"/> 

同樣會爲TextBlock的工作,但它的背景是已經透明

根據this Silverlight不支持FindAncestor

1

使用TemplateBinding:

    <Border Background="{TemplateBinding Background}">       
        <TextBlock Background="{TemplateBinding Background}" Text="something"/>       
       </Border> 

只需設置無論是在你的用戶控件的頂級控件(在我的情況下邊框),並使用TemplateBinding背景TextBlock的。