создать пользовательский элемент управления в моих окнах 10 UWP приложение под названием CustomControl1
[UWP] Пользовательские управления VisualState не работает
public sealed class CustomControl1 : ButtonBase
{
public CustomControl1()
{
this.DefaultStyleKey = typeof(CustomControl1);
}
}
И стиль по умолчанию в Generic.xaml
<Style TargetType="local:CustomControl1" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomControl1">
<Border>
<TextBlock x:Name="textBlock" Text="This is a text block"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="textBlock.Foreground" Value="Red"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Target="textBlock.TextBlock" Value="Blue"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Проблема в том переднем плане TextBlock в не меняйте на Red
при наведении указателя мыши или на Blue
при нажатии. Но если я меняю базовый класс CustomControl1
на Button
, он отлично работает.
public sealed class CustomControl1 : Button
{
public CustomControl1()
{
this.DefaultStyleKey = typeof(CustomControl1);
}
}
В чем разница между этими двумя случаями?
Я помню, что у всех 'Control' есть MouseOver/Pressed состояние в WPF/Silverlight, почему microsoft удаляет его из uwp? – tao