WPF: Where are the built-in styles defined
up vote
0
down vote
favorite
I have a RepeatButton in a Toolbar. I want it to have the same visual appearance as the ToolBar-Buttons. But ToolBar.ButtonStyleKey doesn't work because of the different TargetType. So where are the built-in styles defined (for various Themes) and how can I clone the ToolBar.ButtonStyle for RepeatButton?
wpf
add a comment |
up vote
0
down vote
favorite
I have a RepeatButton in a Toolbar. I want it to have the same visual appearance as the ToolBar-Buttons. But ToolBar.ButtonStyleKey doesn't work because of the different TargetType. So where are the built-in styles defined (for various Themes) and how can I clone the ToolBar.ButtonStyle for RepeatButton?
wpf
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a RepeatButton in a Toolbar. I want it to have the same visual appearance as the ToolBar-Buttons. But ToolBar.ButtonStyleKey doesn't work because of the different TargetType. So where are the built-in styles defined (for various Themes) and how can I clone the ToolBar.ButtonStyle for RepeatButton?
wpf
I have a RepeatButton in a Toolbar. I want it to have the same visual appearance as the ToolBar-Buttons. But ToolBar.ButtonStyleKey doesn't work because of the different TargetType. So where are the built-in styles defined (for various Themes) and how can I clone the ToolBar.ButtonStyle for RepeatButton?
wpf
wpf
asked Nov 10 at 15:12
ubsch
277
277
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31
add a comment |
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
They are defined in the C:WindowsMicrosoft.NETFramework64v4.0.30319WPFPresentationFramework*
assemblies. You could use a decompiler such as dotPeek to extract the templates, or you can right-click on a control in design mode in Visual Studio or in Blend and choose Edit Template
->Edit a Copy
to copy the default template into your XAML markup.
I tried this and I got the
Template
forToolBar
, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
It's right there:
<Style x:Key="x:Static ToolBar.ButtonStyleKey" TargetType="x:Type Button">
<Setter Property="Control.Foreground" Value="DynamicResource x:Static SystemColors.ControlTextBrushKey"/>
<Setter Property="Control.Padding" Value="2"/>
<Setter Property="Control.BorderThickness" Value="1"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.BorderBrush" Value="Transparent"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Button">
<Border Name="Bd" Background="TemplateBinding Control.Background"
BorderBrush="TemplateBinding Control.BorderBrush"
BorderThickness="TemplateBinding Control.BorderThickness"
Padding="TemplateBinding Control.Padding" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="TemplateBinding Control.HorizontalContentAlignment"
VerticalAlignment="TemplateBinding Control.VerticalContentAlignment"
SnapsToDevicePixels="TemplateBinding UIElement.SnapsToDevicePixels"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƾ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƽ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="false">
<Setter Value="DynamicResource x:Static SystemColors.GrayTextBrushKey" Property="Control.Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
They are defined in the C:WindowsMicrosoft.NETFramework64v4.0.30319WPFPresentationFramework*
assemblies. You could use a decompiler such as dotPeek to extract the templates, or you can right-click on a control in design mode in Visual Studio or in Blend and choose Edit Template
->Edit a Copy
to copy the default template into your XAML markup.
I tried this and I got the
Template
forToolBar
, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
It's right there:
<Style x:Key="x:Static ToolBar.ButtonStyleKey" TargetType="x:Type Button">
<Setter Property="Control.Foreground" Value="DynamicResource x:Static SystemColors.ControlTextBrushKey"/>
<Setter Property="Control.Padding" Value="2"/>
<Setter Property="Control.BorderThickness" Value="1"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.BorderBrush" Value="Transparent"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Button">
<Border Name="Bd" Background="TemplateBinding Control.Background"
BorderBrush="TemplateBinding Control.BorderBrush"
BorderThickness="TemplateBinding Control.BorderThickness"
Padding="TemplateBinding Control.Padding" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="TemplateBinding Control.HorizontalContentAlignment"
VerticalAlignment="TemplateBinding Control.VerticalContentAlignment"
SnapsToDevicePixels="TemplateBinding UIElement.SnapsToDevicePixels"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƾ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƽ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="false">
<Setter Value="DynamicResource x:Static SystemColors.GrayTextBrushKey" Property="Control.Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
add a comment |
up vote
1
down vote
accepted
They are defined in the C:WindowsMicrosoft.NETFramework64v4.0.30319WPFPresentationFramework*
assemblies. You could use a decompiler such as dotPeek to extract the templates, or you can right-click on a control in design mode in Visual Studio or in Blend and choose Edit Template
->Edit a Copy
to copy the default template into your XAML markup.
I tried this and I got the
Template
forToolBar
, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
It's right there:
<Style x:Key="x:Static ToolBar.ButtonStyleKey" TargetType="x:Type Button">
<Setter Property="Control.Foreground" Value="DynamicResource x:Static SystemColors.ControlTextBrushKey"/>
<Setter Property="Control.Padding" Value="2"/>
<Setter Property="Control.BorderThickness" Value="1"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.BorderBrush" Value="Transparent"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Button">
<Border Name="Bd" Background="TemplateBinding Control.Background"
BorderBrush="TemplateBinding Control.BorderBrush"
BorderThickness="TemplateBinding Control.BorderThickness"
Padding="TemplateBinding Control.Padding" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="TemplateBinding Control.HorizontalContentAlignment"
VerticalAlignment="TemplateBinding Control.VerticalContentAlignment"
SnapsToDevicePixels="TemplateBinding UIElement.SnapsToDevicePixels"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƾ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƽ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="false">
<Setter Value="DynamicResource x:Static SystemColors.GrayTextBrushKey" Property="Control.Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
They are defined in the C:WindowsMicrosoft.NETFramework64v4.0.30319WPFPresentationFramework*
assemblies. You could use a decompiler such as dotPeek to extract the templates, or you can right-click on a control in design mode in Visual Studio or in Blend and choose Edit Template
->Edit a Copy
to copy the default template into your XAML markup.
I tried this and I got the
Template
forToolBar
, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
It's right there:
<Style x:Key="x:Static ToolBar.ButtonStyleKey" TargetType="x:Type Button">
<Setter Property="Control.Foreground" Value="DynamicResource x:Static SystemColors.ControlTextBrushKey"/>
<Setter Property="Control.Padding" Value="2"/>
<Setter Property="Control.BorderThickness" Value="1"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.BorderBrush" Value="Transparent"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Button">
<Border Name="Bd" Background="TemplateBinding Control.Background"
BorderBrush="TemplateBinding Control.BorderBrush"
BorderThickness="TemplateBinding Control.BorderThickness"
Padding="TemplateBinding Control.Padding" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="TemplateBinding Control.HorizontalContentAlignment"
VerticalAlignment="TemplateBinding Control.VerticalContentAlignment"
SnapsToDevicePixels="TemplateBinding UIElement.SnapsToDevicePixels"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƾ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƽ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="false">
<Setter Value="DynamicResource x:Static SystemColors.GrayTextBrushKey" Property="Control.Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
They are defined in the C:WindowsMicrosoft.NETFramework64v4.0.30319WPFPresentationFramework*
assemblies. You could use a decompiler such as dotPeek to extract the templates, or you can right-click on a control in design mode in Visual Studio or in Blend and choose Edit Template
->Edit a Copy
to copy the default template into your XAML markup.
I tried this and I got the
Template
forToolBar
, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
It's right there:
<Style x:Key="x:Static ToolBar.ButtonStyleKey" TargetType="x:Type Button">
<Setter Property="Control.Foreground" Value="DynamicResource x:Static SystemColors.ControlTextBrushKey"/>
<Setter Property="Control.Padding" Value="2"/>
<Setter Property="Control.BorderThickness" Value="1"/>
<Setter Property="Control.Background" Value="Transparent"/>
<Setter Property="Control.BorderBrush" Value="Transparent"/>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.VerticalAlignment" Value="Center"/>
<Setter Property="Control.HorizontalContentAlignment" Value="Center"/>
<Setter Property="Control.VerticalContentAlignment" Value="Center"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="x:Type Button">
<Border Name="Bd" Background="TemplateBinding Control.Background"
BorderBrush="TemplateBinding Control.BorderBrush"
BorderThickness="TemplateBinding Control.BorderThickness"
Padding="TemplateBinding Control.Padding" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="TemplateBinding Control.HorizontalContentAlignment"
VerticalAlignment="TemplateBinding Control.VerticalContentAlignment"
SnapsToDevicePixels="TemplateBinding UIElement.SnapsToDevicePixels"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƻ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƺ" Property="Border.Background"/>
</Trigger>
<Trigger Property="ButtonBase.IsPressed" Value="true">
<Setter TargetName="Bd" Value="StaticResource ƾ" Property="Border.BorderBrush"/>
<Setter TargetName="Bd" Value="StaticResource ƽ" Property="Border.Background"/>
</Trigger>
<Trigger Property="UIElement.IsEnabled" Value="false">
<Setter Value="DynamicResource x:Static SystemColors.GrayTextBrushKey" Property="Control.Foreground"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
edited Nov 14 at 15:59
answered Nov 13 at 10:06


mm8
80.3k81831
80.3k81831
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
add a comment |
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
Thanks mm8, I tried this and I got the Template for ToolBar, but not the style for ToolBarButton. The search ends at ToolBarButtonStyleKey, but can't find ToolBarButtonStyle for WPF.
– ubsch
Nov 14 at 15:26
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
@ubsch: It's right there. See my edit.
– mm8
Nov 14 at 15:59
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
Thanks! I think I have to get more into dotPeek.
– ubsch
Nov 15 at 19:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240293%2fwpf-where-are-the-built-in-styles-defined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I can't help you with the 1st part of the question (Where are the default styles defined? In some theme(s), which again are stored in some DLL file, somewhere, i guess...). But to get the (default) control template for a control in XAML form, you might follow the advice given here: stackoverflow.com/a/26548268/2819245.
– elgonzo
Nov 10 at 15:31