Skip to content

FlatButton

JaykeBird edited this page Feb 21, 2023 · 11 revisions

Back to home | Back to Reference | View raw text

FlatButton class

Description

A button with a custom, flat style and additional funcionality. Use SelectOnClick to have the button act like a toggle button.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph SolidShineUi
  SolidShineUi.FlatButton[[FlatButton]]
  end
  subgraph System.Windows.Controls.Primitives
System.Windows.Controls.Primitives.ButtonBase[[ButtonBase]]
  end
System.Windows.Controls.Primitives.ButtonBase --> SolidShineUi.FlatButton
Loading

Members

Properties

Public properties

Type Name Methods
Brush Background
Get or set the brush used for the background of the control.
get, set
Brush BorderBrush
Get or set the brush used for the border around the edges of the control.
get, set
Brush BorderDisabledBrush
Get or set the brush used for the border of the control when the control is disabled.
get, set
Brush BorderHighlightBrush
Get or set the brush used for the border while the control has the mouse over it (or it has keyboard focus).
get, set
Brush BorderSelectedBrush
Get or set the brush used for the border while the control is selected
(i.e. the IsSelected property is true).
get, set
Thickness BorderSelectionThickness
Get or set the thickness of the border around the button, while the button is in a selected ( IsSelected ) state.
get, set
Thickness BorderThickness
Get or set the thickness of the border around the button.
get, set
Brush ClickBrush
Get or set the brush used for the background of the control while the mouse is clicking it.
get, set
ColorScheme ColorScheme
Get or set the color scheme to apply to this button. The color scheme can quickly apply a whole visual style to your control.
get, set
CornerRadius CornerRadius
Get or set the corner radius (or radii) to use for the button and its border. Can be used to create a rounded button.
get, set
Brush DisabledBrush
Get or set the brush used for the background of the control when the control is disabled.
get, set
Brush HighlightBrush
Get or set the brush used for the background of the control while the mouse is over it, or it has keyboard focus.
get, set
bool IsDefault
Get or set if this button is the default button in the dialog or window it is located in. May not currently function correctly.
get, set
bool IsDefaulted
Specifies whether or not this button is the button that would be invoked when Enter is pressed.
get
bool IsSelected
Gets or sets whether this button is selected. This property (combined with SelectOnClick ) allows the button to function like a ToggleButton.
get, set
bool SelectOnClick
Gets or sets whether the button should change its IsSelected property when a click is performed. With this enabled, this allows the button to take on the functionality of a ToggleButton.
get, set
Brush SelectedBrush
Get or set the brush used for the background of this button while it is selected
(i.e. the IsSelected property is true).
get, set
bool TransparentBack
Get or set whether the button should have a transparent background when the button is not focused.
get, set
bool UseAccentColors
Get or set if the button should use the accent colors of the color scheme, rather than the standard colors.
get, set

Methods

Public Static methods

Returns Name
bool GetIsMouseDown(DependencyObject obj)
Get the IsMouseDown property for a FlatButton.
void OnColorSchemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Perform an action when the ColorScheme property has changed. Primarily used internally.
void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Perform an action when a property of an object has changed. Primarily used internally.
void OnTransparentBackChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Perform an action when a property of an object has changed. Primarily used internally.
void OnUseAccentColorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Perform an action when a property of an object has changed. Primarily used internally.

Protected Static methods

Returns Name
void SetIsMouseDown(DependencyObject obj, bool value)
Set the IsMouseDown property for a FlatButton.

Public methods

Returns Name
void ApplyColorScheme(...)
Apply a color scheme to this control, and set some other optional appearance settings. The color scheme can quickly apply a whole visual style to the control.
void DoClick()
Perform a click programattically. The button responds the same way as if it was clicked by the user.

Protected methods

Returns Name
void OnClick()
Defines the actions the button performs when it is clicked.

Details

Summary

A button with a custom, flat style and additional funcionality. Use SelectOnClick to have the button act like a toggle button.

Inheritance

  • ButtonBase

Constructors

FlatButton

public FlatButton()
Summary

Create a new FlatButton.

Methods

OnColorSchemeChanged

public static void OnColorSchemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Arguments
Type Name Description
DependencyObject d The object containing the property that changed.
DependencyPropertyChangedEventArgs e Event arguments about the property change.
Summary

Perform an action when the ColorScheme property has changed. Primarily used internally.

OnTransparentBackChanged

public static void OnTransparentBackChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Arguments
Type Name Description
DependencyObject d The object containing the property that changed.
DependencyPropertyChangedEventArgs e Event arguments about the property change.
Summary

Perform an action when a property of an object has changed. Primarily used internally.

OnUseAccentColorsChanged

public static void OnUseAccentColorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Arguments
Type Name Description
DependencyObject d The object containing the property that changed.
DependencyPropertyChangedEventArgs e Event arguments about the property change.
Summary

Perform an action when a property of an object has changed. Primarily used internally.

ApplyColorScheme [1/2]

public void ApplyColorScheme(ColorScheme cs, bool transparentBack, bool useAccentColors)
Arguments
Type Name Description
ColorScheme cs The color scheme to apply
bool transparentBack Set if the button should have no background when not focused or highlighted. This can also be achieved with the TransparentBack property.
bool useAccentColors Set if accent colors should be used for this button, rather than the main color scheme colors.
This can also be achieved with the UseAccentColors property.
Summary

Apply a color scheme to this control, and set some other optional appearance settings. The color scheme can quickly apply a whole visual style to the control.

ApplyColorScheme [2/2]

public void ApplyColorScheme(HighContrastOption hco, bool transparentBack)
Arguments
Type Name Description
HighContrastOption hco The high-contrast color scheme to apply.
bool transparentBack Set if the button should have no background when not focused or highlighted. This can also be achieved with the TransparentBack property.
Summary

Apply a color scheme to this control. The color scheme can quickly apply a whole visual style to the control.

SetIsMouseDown

protected static void SetIsMouseDown(DependencyObject obj, bool value)
Arguments
Type Name Description
DependencyObject obj The FlatButton to apply the property change to.
bool value The new value to set for the property.
Summary

Set the IsMouseDown property for a FlatButton.

GetIsMouseDown

public static bool GetIsMouseDown(DependencyObject obj)
Arguments
Type Name Description
DependencyObject obj The Flatbutton to get the property value from.
Summary

Get the IsMouseDown property for a FlatButton.

OnIsSelectedChanged

public static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Arguments
Type Name Description
DependencyObject d The object containing the property that changed.
DependencyPropertyChangedEventArgs e Event arguments about the property change.
Summary

Perform an action when a property of an object has changed. Primarily used internally.

DoClick

public void DoClick()
Summary

Perform a click programattically. The button responds the same way as if it was clicked by the user.

OnClick

protected override void OnClick()
Summary

Defines the actions the button performs when it is clicked.

Properties

Background

public Brush Background { get; set; }
Summary

Get or set the brush used for the background of the control.

ClickBrush

public Brush ClickBrush { get; set; }
Summary

Get or set the brush used for the background of the control while the mouse is clicking it.

SelectedBrush

public Brush SelectedBrush { get; set; }
Summary

Get or set the brush used for the background of this button while it is selected (i.e. the IsSelected property is true).

HighlightBrush

public Brush HighlightBrush { get; set; }
Summary

Get or set the brush used for the background of the control while the mouse is over it, or it has keyboard focus.

DisabledBrush

public Brush DisabledBrush { get; set; }
Summary

Get or set the brush used for the background of the control when the control is disabled.

BorderDisabledBrush

public Brush BorderDisabledBrush { get; set; }
Summary

Get or set the brush used for the border of the control when the control is disabled.

BorderBrush

public Brush BorderBrush { get; set; }
Summary

Get or set the brush used for the border around the edges of the control.

BorderHighlightBrush

public Brush BorderHighlightBrush { get; set; }
Summary

Get or set the brush used for the border while the control has the mouse over it (or it has keyboard focus).

BorderSelectedBrush

public Brush BorderSelectedBrush { get; set; }
Summary

Get or set the brush used for the border while the control is selected (i.e. the IsSelected property is true).

ColorScheme

public ColorScheme ColorScheme { get; set; }
Summary

Get or set the color scheme to apply to this button. The color scheme can quickly apply a whole visual style to your control.

TransparentBack

public bool TransparentBack { get; set; }
Summary

Get or set whether the button should have a transparent background when the button is not focused.

UseAccentColors

public bool UseAccentColors { get; set; }
Summary

Get or set if the button should use the accent colors of the color scheme, rather than the standard colors.

BorderThickness

public Thickness BorderThickness { get; set; }
Summary

Get or set the thickness of the border around the button.

BorderSelectionThickness

public Thickness BorderSelectionThickness { get; set; }
Summary

Get or set the thickness of the border around the button, while the button is in a selected ( IsSelected ) state.

CornerRadius

public CornerRadius CornerRadius { get; set; }
Summary

Get or set the corner radius (or radii) to use for the button and its border. Can be used to create a rounded button.

IsSelected

public bool IsSelected { get; set; }
Summary

Gets or sets whether this button is selected. This property (combined with SelectOnClick ) allows the button to function like a ToggleButton.

Remarks

A selected button will have a slightly different visual appearance to differentiate it as being selected. This will include, by default, the border being a bit thicker. This can be changed via the FlatButton.BorderSelectionThickness property. You can also directly edit the brushes used via the FlatButton.SelectedBrush and FlatButton.BorderSelectedBrush properties.

SelectOnClick

public bool SelectOnClick { get; set; }
Summary

Gets or sets whether the button should change its IsSelected property when a click is performed. With this enabled, this allows the button to take on the functionality of a ToggleButton.

Remarks

While SelectOnClick is true, the button will toggle between FlatButton.IsSelected being true and false (similar to a ToggleButton). A selected button will, by default, have some visual differences to help make it look distinct from unselected buttons. The button's Click event will still be raised while this property is set to true , but the event occurs after the IsSelected property has already changed. While you could use the Click event to check when the button's IsSelected property is changed, it is better to use the IsSelectedChanged event, in case of situations where IsSelected is changed via methods other than clicking, such as programmatically or via WPF binding.

IsDefault

public bool IsDefault { get; set; }
Summary

Get or set if this button is the default button in the dialog or window it is located in. May not currently function correctly.

IsDefaulted

public bool IsDefaulted { get; }
Summary

Specifies whether or not this button is the button that would be invoked when Enter is pressed.

Events

IsSelectedChanged

public event DependencyPropertyChangedEventHandler IsSelectedChanged
Summary

Raised if the button's IsSelected value is changed. This can be used to have the button act as a ToggleButton.

ColorSchemeChanged

public event DependencyPropertyChangedEventHandler ColorSchemeChanged
Summary

Raised when the ColorScheme property is changed.

RightClick

public event RoutedEventHandler RightClick
Summary

Raised when the user right-clicks on the button, via a mouse click or via the keyboard.

Generated with ModularDoc

Clone this wiki locally