WPF: Inherit Style From Style. BasedOn Is Your Friend

So another quick one.  Say you have a style for creating round buttons, but you don’t want to include a size, how a size be applied without touching the original style?  Well you could just adjust the properties right on the button, but what if you want something a little more reusable?  It’s actually pretty simple, just have one style “inherit” the other.  Well that’s where BasedOn comes in.

Say you have a style named RoundButton.

    <Style x:Key="GlassButton" TargetType="{x:Type Button}">

All you have to do is create a new style:

    <Style x:Key="HeaderButton" BasedOn="{StaticResource GlassButton}" TargetType="{x:Type Button}">
        <Setter Property="Height" Value="20" />
        <Setter Property="Width" Value="20" />

As you can see, it’s pretty simple using the BasedOn keyword. Now when the HeaderButton style is applied to the button, it will take on the properties of the RoundButton style and the HeaderButton one. Nice huh?

WPF: Hide Built in Header Bar For an Open Window

Ok so this one is a simple one.  Well at least once you see it in action.  Say you want to get rid of the built in windows header bar:

You know, that thing. Well it’s crazy simple. And I mean crazy as in mind boggling, not crazy like dress up your cat in clothes crazy.

All you have to do is set these two properties:

AllowsTransparency="True" WindowStyle="None"

In the window tag at the top of the page. For example:

<Window x:Class="DesCombine.WPF.FileUpload"
  Title="File Upload" Height="350" Width="525" BorderThickness="0" ResizeMode="NoResize"
  WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None">

Only catch is that you have to now supply any useful buttons like Minimize or Close by yourself. But I never said that you wouldn’t. You thought that. You.