Windows Phone 8.1按钮单击事件不起作用

时间:2014-06-26 08:20:28

标签: windows-phone-8 buttonclick

来自的点击选项 没有创建点击事件,我甚至尝试使用MouseLeftButton 但没有任何反应。我会附上我的" xaml"文件看看是什么 错了。唯一的解决方案是放置对象 启动后屏幕代码,并在启动后将可见性设置为true 屏幕结束。我要求一个更好的解决方案来放置我的对象 在Click事件中做出反应。

<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
xmlns:sysctrl="clr-namespace:System.Windows.Controls;assembly=Microsoft.Phone"
x:Class="SplashScreen.MainPage"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
DataContext="{Binding Source={StaticResource Locator}, Path=Main}">

<i:Interaction.Behaviors>
    <ec:DataStateBehavior Binding="{Binding DataLoaded}" 
                          Value="False" 
                          TrueState="Loading"
                          FalseState="Loaded"/>
</i:Interaction.Behaviors>



<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="DataStates">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:2" To="Loaded">
                    <VisualTransition.GeneratedEasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="Loading">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" 
                                                   Storyboard.TargetName="ContentPanel">
                        <DiscreteObjectKeyFrame KeyTime="0">
                            <DiscreteObjectKeyFrame.Value>
                                <Visibility>Collapsed</Visibility>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="Loaded">
                <Storyboard>
                    <DoubleAnimation Duration="0" 
                                     To="0" 
                                     Storyboard.TargetProperty="(UIElement.Opacity)" 
                                     Storyboard.TargetName="stackPanel" 
                                     d:IsOptimized="True"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" 
          Grid.Row="1" 
          Margin="12,0,12,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="67*"/>
            <ColumnDefinition Width="85*"/>
        </Grid.ColumnDefinitions>

        <phone:Pivot  Margin="0,10,0,-160" Grid.ColumnSpan="2" >

            <phone:PivotItem Header="Settings" >
                <StackPanel Grid.RowSpan="2"
                            >
                    <TextBox Name="PrintText"
                         Width="300"
                         Height="196" Margin="66,10,66,274"/>
                    <Button  Click="Button_Click"

                             IsHitTestVisible="True"
                             IsEnabled="True"
                        Width="100"
                        Height="100" RenderTransformOrigin="0.34,-2"
                        Margin="166,0"
                        >
                        <Image Source="upload.png" 
                            Stretch="Fill" 
                            Width="50"
                            Height="50"
                            />
                    </Button>
                </StackPanel>
            </phone:PivotItem>

            <phone:PivotItem Header="View Statistics">
            </phone:PivotItem>

            <phone:PivotItem Header="Notification">
            </phone:PivotItem>
        </phone:Pivot>

    </Grid>
    <StackPanel x:Name="stackPanel" Grid.RowSpan="2">
        <StackPanel.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FFF3F3F3" Offset="0.552"/>
            </LinearGradientBrush>
        </StackPanel.Background>     
        <Image Source="screen_loader.png"
            Width="350"
            Height="350" Margin="65,120"/>
        <ProgressBar Height="10" Margin="0,20,0,0" IsIndeterminate="True"/>
    </StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:1)

这是一个XY问题。我想你要做的就是检测Tap事件,当用户点击按钮时会引发事件。只需将其处理的事件更改为Tap。