2017-01-05 28 views
0

考慮:有條件支持算法FMP在XAML風格

<Style x:Key="ThirdLevelGroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource MetroGroupBox}"> 
    <Setter Property="Background" Value="{DynamicResource AccentColorBrush3}" /> 
</Style> 

<Style x:Key="SecondLevelGroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource MetroGroupBox}"> 
    <Setter Property="Background" Value="{DynamicResource AccentColorBrush2}" /> 
</Style> 

<Style TargetType="GroupBox" x:Key="WidgetControlTemplateStyle" BasedOn="{StaticResource ThirdLevelGroupBoxStyle}"> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding CanExecuteClickCommand}" Value="True"> 
      <!-- TODO: SecondLevelGroupBoxStyle --> 
      <Setter Property="Background" Value="{DynamicResource AccentColorBrush2}" /> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

<ControlTemplate TargetType="ContentControl" x:Key="WidgetControlTemplate"> 
    <GroupBox ... Style="{StaticResource WidgetControlTemplateStyle}"> 
     <ContentPresenter /> 
    </GroupBox> 
</ControlTemplate> 

ControlTemplate有風格WidgetControlTemplate。我想根據ThirdLevelGroupBoxStyleSecondLevelGroupBoxStyle有條件地(BasedOnWidgetControlTemplate款式,以避免XAML重複。有沒有辦法做到這一點?

如果我不能這樣做,我必須重複SecondLevelGroupBoxStyle的定義。

回答

0

有沒有辦法做到這一點?

不,不是在XAML。設計時必須知道基於樣式的基礎樣式。

如果我不能這樣做,我必須重複SecondLevelGroupBoxStyle的定義。

由於您有兩種基於MetroGroupBox的不同樣式,基於這兩種樣式的每種樣式都將始終是單獨樣式,因爲您無法將單一樣式基於多種樣式。

您可以做的是使用觸發器,將GroupBox的Background屬性設置爲AccentColorBrush3或AccentColorBrush2,而不是嘗試從另一個樣式繼承此屬性。看起來你已經在WidgetControlTemplateStyle樣式中做了這個。是的,如果ThirdLevelGroupBoxStyle/SecondLevelGroupBoxStyle設置多個屬性,您也必須在WidgetControlTemplateStyle中設置所有這些屬性。

恐怕沒有辦法解決這個問題,除非你將兩種風格合併爲一個或以某種方式以編程方式定義它們。

+0

謝謝,至少我知道沒有好的方法來做到這一點。是的,這是超過1個屬性;( –