2017-09-06 34 views
0

這是WPF GroupBox的樣式。 我可以從App.xaml.cs中定義的屬性中設置Groupbox背景和Groupbox邊框顏色的值,如圖所示。使用App.xaml.cs中的屬性設置GroupBox標題模板的前景

<Style x:Key="StyleGroupBox1" TargetType="GroupBox"> 
      <Setter Property="Background" > 
       <Setter.Value> 
        <Binding Path="GroupBox_Background" Source="{x:Static Application.Current}"/> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="BorderBrush"> 
       <Setter.Value> 
        <Binding Path="Groupbox_BorderColor" Source="{x:Static Application.Current}"/> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="Margin" Value="1,1,1,1"/> 
      <Setter Property="HeaderTemplate"> 
       <Setter.Value> 
        <DataTemplate> 
         <TextBlock Text="{Binding}" FontWeight="Bold" FontFamily="Palatino Linotype" FontSize="17" Foreground="DarkRed" FontStyle="Italic"> 

         </TextBlock> 

        </DataTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

如何設置分組框的相似,在我所設置的組框的背景和BORDERCOLOR(即從我app.xaml.cs定義的屬性)的方式頭模板的前景?即目前標題文本設置爲DarkRed,但如何使用我的App.xaml.cs中的屬性來設置它?

回答

1
<TextBlock 
       Text="{Binding}" 
       FontWeight="Bold" 
       FontFamily="Palatino Linotype" 
       FontSize="17" 
       Foreground="{Binding Source={x:Static Application.Current}, Path=Groupbox_HeaderForegroundColor}" 
       FontStyle="Italic"> 
+0

Vadim Moskvin:好吧,談談它......感謝..它的工作。我使用了錯誤的TargetType。我的錯..:-)。 –