0
我目前工作在Windows通用的應用程序工作,我定義了一個名爲UserControl
IconButton
VisualStateManager不是通用的應用
IconButton.xaml
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="Common">
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation To="Red" Storyboard.TargetName="path" Storyboard.TargetProperty="(Fill).(SolidColorBrush.Color)" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid>
<Path x:Name="path" Data="{x:Bind IconPathData, Mode=OneWay}" Stretch="UniformToFill" Fill="White" />
</Grid>
IconButton。 xaml.cs
public sealed partial class IconButton : UserControl
{
public static readonly DependencyProperty IconPathDataProperty = DependencyProperty.Register("IconPathData", typeof(string), typeof(IconButton), new PropertyMetadata(""));
public string IconPathData
{
get { return (string)GetValue(IconPathDataProperty); }
set { SetValue(IconPathDataProperty, value); }
}
public IconButton()
{
InitializeComponent();
}
private void UserControl_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, MouseOver.Name, true);
}
}
根據MSDNGoToState
方法預計VisualState
與給定的名稱傳遞給該方法。在我的情況下,VisualState
與x:Name="MouseOver"
,所以GoToState
應該能夠找到這個。
不幸的是GoToState
總是返回false,只有當它找不到具有給定名稱的VisualState
時纔會發生。
我真的不知道該怎麼做才能解決這個問題。文檔非常簡單,Web上的幾個例子與我一樣,但它們能夠正常工作。
你能告訴我我做錯了什麼,以及如何解決它?
嘗試'PointerOver',而不是'MouseOver' –
'MouseOver'是'VisualState'的只是名字,應該是無關的'GoToState'只要我提供正確的名稱(請參閱MSDN鏈接)。如如果我用'PointerOver'替換'MouseOver',預計沒有什麼變化。 – TorbenJ