ModernWpf
ModernWpf copied to clipboard
How to extend a control element, such as button?
I hava a simple class that extends an oridinary button. However, in the UI the button is not styled, unlike other simple System.Windows.Controls.Button objects. How do I make it follow the same ModernWpf styling?
public partial class JobButton : Button
{
readonly string startJob = "Start";
readonly string endJob = "Stop";
public void ToggleJob()
{
if (MainWindow.IsJobStarted)
{
Content = startJob;
}
else
{
Content = endJob;
}
}
}
<local:JobButton Content="Start"
Margin="10,0,0,10"
Click="ToggleItemEnterJob"
Height="30"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Width="120" />
Make your style based on overrides.
I've been adding a BasedOn attribute. Not sure if this is the right way, but it seems to work:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
<Setter Property="MinWidth" Value="70" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="Margin" Value="5,0,0,0" />
</Style>