markltx
markltx

Reputation: 709

How to use standard Button style in WPF ToolBar?

I want the Buttons in my WPF ToolBar to look like standard Buttons. That is, I want them to use the default Button style, but the ToolBar applies its own "ToolBar.ButtonStyleKey" style to the Buttons. I have tried this...

<ToolBar>
    <Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>

... but the Button in the ToolBar still looks just like a TextBlock (no border, background, etc.).

Upvotes: 3

Views: 2464

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222582

Just use without any style,

<ToolBar>
       <Button Content="A Button" />
</ToolBar>

EDIT Misread the question, this should work fine without any issue

<ToolBar>
    <Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>

Upvotes: 1

mm8
mm8

Reputation: 169200

Your example works fine for me on Windows 10.

You could also try this:

<ToolBar>
    <ToolBar.Resources>
        <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" />
    </ToolBar.Resources>
    <Button Content="A Button" />
</ToolBar>

Upvotes: 4

Related Questions