1
我寫一個樣本窗口通用的應用程序與3狀態按鈕(普通,重點和按下)按鈕點擊不解僱首次的[Windows 8.1/10平板電腦僅]
我的代碼如下。
現在我正面臨一個按鈕點擊的問題,當第一次點擊按鈕時,按鈕點擊事件不會被解僱。但第一次點擊之後,它工作正常[問題是Windows平板僅發生,工作在臺式機和筆記本電腦精]
這是衆所周知的問題,或任何東西錯的是我的代碼
CS
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void ButtonClicked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Inside Button clicked:Button");
}
private void ImageClicked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Inside Image clicked:CustomButton");
}
}
XAML
<Page x:Class="App5.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App5"
xmlns:customControls="using:App5.CustomControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Button" HorizontalAlignment="Left" Margin="243,228,0,0" VerticalAlignment="Top" Width="229" Height="104" Click="ButtonClicked" />
<customControls:CalcButton Content="Button" HorizontalAlignment="Left" Margin="705,231,0,0" VerticalAlignment="Top" Height="101" Width="262" NormalImage="/Assets/Logo.scale-100.png" PressedImage="/Assets/SmallLogo.scale-100.png" HoverImage="/Assets/SplashScreen.scale-100.png" Click="ImageClicked"/>
</Grid>
</Page>
Generic.XAML
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App5"
xmlns:customControls="using:App5.CustomControl">
<Style TargetType="customControls:CalcButton">
<Setter
Property="HorizontalAlignment"
Value="Stretch" />
<Setter
Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="customControls:CalcButton">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition To="PointerOver"
GeneratedDuration="0:0:0" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="ButtonBrush"
Storyboard.TargetProperty="Source">
<DiscreteObjectKeyFrame KeyTime="0:0:0"
Value="{Binding HoverImage, RelativeSource={RelativeSource TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="ButtonBrush"
Storyboard.TargetProperty="Source">
<DiscreteObjectKeyFrame KeyTime="0:0:0"
Value="{Binding PressedImage, RelativeSource={RelativeSource TemplatedParent}}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image x:Name="ButtonBrush" Source="{TemplateBinding NormalImage}" Stretch="Fill" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
集[clickmode](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.clickmode)=按下的按鈕。 –
我們試過了。但沒有按預期工作。 –
真的嗎?嗯,沒想到的是,將不得不稍後再回頭看看,對此感到遺憾。 –