Hello,
Welcome to our Microsoft Q&A platform!
Button control cannot do this. Because for Button, there is only one click process. The PointerOver state refers to the movement of the cursor within the Button. Once moved out, the PointerOver state cannot be maintained.
According to your needs, you can try to use ToggleButton. Compared to Button, ToggleButton has a Check state, which can be maintained after selection.
xaml
<Page.Resources>
<Flyout x:Name="MyFlyout" Closed="MyFlyout_Closed"/>
</Page.Resources>
<Grid>
<ToggleButton x:Name="TestButton" Click="TestButton_Click"
Content="Click Me" FlyoutBase.AttachedFlyout="{StaticResource MyFlyout}"/>
</Grid>
xaml.cs
private void TestButton_Click(object sender, RoutedEventArgs e)
{
if (!MyFlyout.IsOpen)
{
FlyoutBase.ShowAttachedFlyout(TestButton);
}
}
private void MyFlyout_Closed(object sender, object e)
{
TestButton.IsChecked = false;
}
In terms of style, you can modify the default style:
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleButtonForegroundChecked}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleButtonBorderBrushChecked}" />
</ObjectAnimationUsingKeyFrames>
<PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
</Storyboard>
</VisualState>
Thanks.