Create Styles That Adapt to the Current OS Theme : Style « Windows Presentation Foundation « VB.Net






Create Styles That Adapt to the Current OS Theme

Create Styles That Adapt to the Current OS Theme
     

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="134" Width="200">

    <Window.Resources>
    <SolidColorBrush x:Key="ButtonText" Color="Black"/>

    <Style
        x:Key="CustomProgressBarStyle"
        TargetType="{x:Type ProgressBar}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate 
                        TargetType="{x:Type ProgressBar}">
                    <Grid MinHeight="20" MinWidth="240">
                        <Border 
                          Name="PART_Track" 
                          Background="{DynamicResource 
                            {x:Static SystemColors.InactiveCaptionBrushKey}}"
                          BorderBrush="{DynamicResource 
                            {x:Static SystemColors.InactiveBorderBrushKey}}"
                          BorderThickness="1" 
                              />
                        <Border 
                          Name="PART_Indicator" 
                          Background="{DynamicResource 
                            {x:Static SystemColors.ActiveCaptionBrushKey}}"
                          BorderBrush="{DynamicResource 
                            {x:Static SystemColors.ActiveBorderBrushKey}}"
                          BorderThickness="1" 
                          HorizontalAlignment="Left" 
                             />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    </Window.Resources>


    <StackPanel>
        <ProgressBar Value="30" 
                     HorizontalAlignment="Center"
                     Margin="4"
                     Style="{DynamicResource CustomProgressBarStyle}"/>
        <Button Margin="4" 
                Content="Custom Brush" 
                Foreground="{DynamicResource ButtonText}"/>
        <Button Margin="4" 
                Content="System Brush" 
                Foreground="{DynamicResource 
                   {x:Static SystemColors.ActiveCaptionBrushKey}}"/>
    </StackPanel>
</Window>

   
    
    
    
    
  








Related examples in the same category

1.Property Trigger: mouse over and focusedProperty Trigger: mouse over and focused
2.Multi Data Trigger DemoMulti Data Trigger Demo
3.Button Based On Style with Target TypeButton Based On Style with Target Type
4.Button With Local StyleButton With Local Style
5.Graphics StylesGraphics Styles
6.Reuse Font With StylesReuse Font With Styles
7.Style InheritanceStyle Inheritance
8.Override Style PropertiesOverride Style Properties
9.Set OverridesDefaultStyle to trueSet OverridesDefaultStyle to true
10.Inherit from a Common Base StyleInherit from a Common Base Style
11.Add any overriding property valuesAdd any overriding property values
12.Clear customized style with NullClear customized style with Null
13.Create a Named StyleCreate a Named Style
14.Applying a Consistent Margin with a StyleApplying a Consistent Margin with a Style
15.Style applied to a Button elementStyle applied to a Button element
16.Create a custom Style and use it for Button with Style element and Setter elementCreate a custom Style and use it for Button with Style element and Setter element
17.Style targeting a specific type of element(Button)Style targeting a specific type of element(Button)
18.Extending a Style using the BasedOn attributeExtending a Style using the BasedOn attribute
19.Target Type DerivativesTarget Type Derivatives
20.Use number substitutions for different culture settingsUse number substitutions for different culture settings
21.Implicit use of a StyleImplicit use of a Style
22.Create a Typed Style for ButtonCreate a Typed Style for Button
23.The dash style of a line is specified by the StrokeDashArray property that gets or sets a collection of double variablesThe dash style of a line is specified by the StrokeDashArray property that gets or sets a collection of double variables
24.Create a style for use as a FocusVisualStyle on a control.Create a style for use as a FocusVisualStyle on a control.
25.Style with Property Trigger.xamlStyle with Property Trigger.xaml
26.Set a Style ProgrammaticallySet a Style Programmatically