2011-07-13 94 views
1

我有一個文本框樣式與在外部資源字典文件中定義的一個鍵,然後我試圖定義一個新的隱式文本框樣式從資源字典中設置「鍵控」樣式,所以基本上我想從資源字典中選擇作爲TextBox默認值的樣式,但我無法從中刪除Key,因爲它被其他代碼使用。Silverlight應用隱式樣式,設置其他樣式

<ResourceDictionary Source="FileWithNiceTextBoxStyle.xaml"/> 
<Style TargetType="TextBox"> 
    <Setter Property="Style" Value="{StaticResource NiceTextBoxStyle}"/> 
</Style> 

但是,這不起作用,並導致Visual Studio崩潰。

回答

2

使用BasedOn屬性:

<Style TargetType="TextBox" x:Key="GlobalTextBox"> 
    <Setter Property="Background" Value="Pink"/> 
</Style> 
<Style TargetType="TextBox" BasedOn="{StaticResource GlobalTextBox}"></Style> 
... 
<TextBox Text="I have pink background"/>