I have overriden the WPF default Maximize, Minimize buttons like explained here. But, in my case, instead of using an Image
to override background image for that buttons, I wanted to add my own template.
So I created a ResourceDictionary
that applies a style for Maximize/Minimize/Restore/Close buttons.
The thing is that I override the template. As an example, see the PART_MINIMIZE button:
<Button x:Name="PART_MINIMIZE"
Width="30"
Height="20"
Margin="0,0,4,0"
HorizontalAlignment="Center"
Template="{DynamicResource MinimizeButton}"
VerticalAlignment="Center"
DockPanel.Dock="Right">
</Button>
The DynamicResource called MinimizeButton stablishes the full template. The problem comes when I click the button. As I override the Template
part, it has no behaviour defined by me by default. But I want to keep Maximize/Minimize/Restore/Close behaviour by default, without overriding it. So...
How can I say in the template to inherit the behaviour of the button? Or how to simulate them?
Thanks!
There is not much to inherit. I suggest you write simple handlers and assign them for button click events. Handlers can be as follows:
Operation with the
Window
should be placed in a special class that would be available from XAML, like that:Operation
Close
:Operation
Hide
:This uses
ToggleButton
because he has propertyIsChecked
accessible via a trigger. These properties - attached depending properties.Listing of
WindowBehaviours
class:Samples of using
ToggleButtons
withWindowBehaviours
class:CloseButton
HideButton
FullScreenButton
i think you should not override the template as it looses basic operations of the control what you should is set the contentTemplate not the template as contenttemplate defines how will your button will look like without halting its basic functions..
this is how you can edit the contenttemplate of button..
if you want to set how your button should look like in app.xaml just set it set its datatemplate like this..
us this datatemplate on your button in xaml like this..