边界控制的UWP默认样式



在哪里可以找到UWP的边境管制默认样式?

我正在尝试更改默认样式,以便onmouseover将更改背景颜色。

通常你可以在这里找到默认样式:

C: \Program Files(x86(\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic\Generic.xaml

然而,我似乎找不到border类的默认样式。

如果您想在鼠标悬停时更改Border的背景色,可以使用VisualStateManager进行更改。您需要在代码后面调用VisualStateManager.GoToState()方法来响应PointerEnter事件,并在视觉状态下激活"PointerOver"。此外,VisualStateManager状态通常应用于控件(从Windows.UI.Xaml.Control.controls派生(,但Border不是从Control派生的。因此,最好将Border放入用户控件中。例如:

主页.xaml:

<Grid>
<UserControl PointerEntered="Border_PointerEntered" PointerExited="Border_PointerExited" x:Name="MyControl">
<Border x:Name="MyBorder" Height="30" VerticalAlignment="Top" Margin="50,0" Background="Red">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Target="MyBorder.Background" Value="Red"></Setter>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="MyBorder.Background" Value="Green"></Setter>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</UserControl>
</Grid>

主页.xaml.cs:

private void Border_PointerEntered(object sender, PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(MyControl, "PointerOver", false);
}
private void Border_PointerExited(object sender, PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(MyControl, "Normal", false);
}

更新:

您可以直接在Border中订阅PointerEntered和PointerExited事件,然后在不使用userControl的情况下更改这些事件的背景。

.xaml:

<Grid>
<Border x:Name="MyBorder" Height="30" VerticalAlignment="Top" Margin="50,0" Background="Red" PointerEntered="Border_PointerEntered" PointerExited="Border_PointerExited">
</Border>
</Grid>

.cs:

private void Border_PointerEntered(object sender, PointerRoutedEventArgs e)
{
MyBorder.Background = new SolidColorBrush(Colors.Green);
}
private void Border_PointerExited(object sender, PointerRoutedEventArgs e)
{
MyBorder.Background = new SolidColorBrush(Colors.Red);
}

最新更新