2009-02-10 9 views
5

मेरे पास थीम्स/जेनेरिक.एक्सएएमएल में निम्न बटन शैली है और मैं इसे अपने WPF एप्लिकेशन में हर जगह बटन पर लागू करना चाहता हूं।थीम्स/जेनेरिक.एक्सएएमएल को window1.xaml से कैसे कनेक्ट करें?

उदाहरण के लिए मैं इसे अपने window1.xaml से कैसे कनेक्ट करूं?

<Style TargetType="{x:Type Button}"> 
    <Setter Property="SnapsToDevicePixels" Value="true"/> 
    <Setter Property="OverridesDefaultStyle" Value="true"/> 
    <Setter Property="MinHeight" Value="23"/> 
    <Setter Property="MinWidth" Value="75"/> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type Button}"> 
     <Border 
      x:Name="Border" 
      CornerRadius="2" 
      BorderThickness="1" 
      Background="#C0C0C0" 
      BorderBrush="#404040"> 
      <ContentPresenter 
      Margin="2" 
      HorizontalAlignment="Center" 
      VerticalAlignment="Center" 
      RecognizesAccessKey="True"/> 
     </Border> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsKeyboardFocused" Value="true"> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#202020" /> 
      </Trigger> 
      <Trigger Property="IsDefaulted" Value="true"> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#202020" /> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="true"> 
      <Setter TargetName="Border" Property="Background" Value="#808080" /> 
      </Trigger> 
      <Trigger Property="IsPressed" Value="true"> 
      <Setter TargetName="Border" Property="Background" Value="#E0E0E0" /> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#606060" /> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="false"> 
      <Setter TargetName="Border" Property="Background" Value="#EEEEEE" /> 
      <Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" /> 
      <Setter Property="Foreground" Value="#888888"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 
+2

मैं जानता हूँ कि यह एक पुराने सवाल है ... लेकिन मैं सुझाव दूंगा कि यदि आप केवल डिफ़ॉल्ट बटन शैली को बदलना चाहते हैं ... कि आप उपरोक्त xaml को अपनी App.xaml फ़ाइल में ले जाएं। जेनेरिक.एक्सएएमएल के पास डब्ल्यूपीएफ की थीम स्टाइल के लिए फॉलबैक तंत्र होने का एक विशिष्ट उद्देश्य है। इस विषय पर अधिक जानकारी के साथ नीचे दिए गए लिंक (गीत द्वारा) को अन्य स्टैक ओवरफ्लो पोस्ट पर देखें। – cplotts

+1

हेक, मुददिब का उत्तर नीचे ... उदाहरण के बारे में बताता है कि मैं क्या कह रहा हूं ... Generic.xaml की बजाय DefaultStyles.xaml विलय करके ... :-) – cplotts

उत्तर

8
अपने Widow1.xaml में

(या अपने App.xaml, करने के लिए बदल रहा है) ......

<Window1.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="DefaultStyles.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Window1.Resources> 
+0

यह है, धन्यवाद! –

संबंधित मुद्दे