Hello,
Welcome to Microsoft Q&A,
A simple way to set the background color of controls is to custom control template. We use control template to customize a control’s visual structure and visual behavior.
For convenience, we can change the visual structure of a control based on existing style. Check the following steps:
- Enter
Style="{StaticResource ToggleButtonRevealStyle}"
in theToggleButton
tag, click ToggleButtonRevealStyle with the mouse and press F12, or right-clickToggleButtonRevealStyle
and select Go To Definition, then we can find the definition ofToggleButtonRevealStyle
. Copy the definition ofToggleButtonRevealStyle
toPage.Resources
of the current page and renamed it. Make sure the ToggleButton control appliies the style. - Find the
VisualState
whose Name isNormal
, change the value ofRootGrid.Background
toRed
and add aSetter
statement:
……<VisualState x:Name="Normal"> <VisualState.Setters> <Setter Target="RootGrid.Background" Value="red"/> <Setter Target="ContentPresenter.Content" Value="in Uhchecked"/> </VisualState.Setters>
</VisualState> - Find the
VisualState
whose Name isPointerOver
, and add aSetter
statement:<Setter Target="ContentPresenter.Content" Value="in Uhchecked"/>
- Find the
VisualState
whose Name isPressed
, and add aSetter
statement:<Setter Target="ContentPresenter.Content" Value="in Uhchecked"/>
- Find the
VisualState
whose Name isChecked
, and add aSetter
statement:<Setter Target="ContentPresenter.Content" Value="in Checked"/>
- Find the
VisualState
whose Name isCheckedPointerOver
, and add aSetter
statement:<Setter Target="ContentPresenter.Content" Value="in Checked"/>
- Find the
VisualState
whose Name isCheckedPressed
, and add aSetter
statement:<Setter Target="ContentPresenter.Content" Value="in Checked"/>
RootGrid
is the Name of the root element of the ToggleButton. And the ContentPresenter is used to display the content of a control.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.