Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Silverlight中为WP7禁用按钮单击效果?_Silverlight_Windows Phone 7 - Fatal编程技术网

如何在Silverlight中为WP7禁用按钮单击效果?

如何在Silverlight中为WP7禁用按钮单击效果?,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我正在使用Silverlight+XNA创建一个WP7应用程序。在这种情况下,我使用图像作为按钮(Silverlight元素)的背景,每当我按下按钮时,就会出现白色背景。我怎样才能摆脱它?它似乎是按钮的默认属性 您必须为按钮创建一个样式。为每个可视状态更改按钮的属性。如设置不同状态(如按下、正常等)的背景图像属性,并将该样式应用于按钮。 Microsoft Expression Blend将通过几个简单的步骤帮助您完成此操作。您必须为按钮创建样式。为每个可视状态更改按钮的属性。如设置不同状态(如

我正在使用Silverlight+XNA创建一个WP7应用程序。在这种情况下,我使用图像作为按钮(Silverlight元素)的背景,每当我按下按钮时,就会出现白色背景。我怎样才能摆脱它?它似乎是按钮的默认属性

您必须为按钮创建一个样式。为每个可视状态更改按钮的属性。如设置不同状态(如按下、正常等)的背景图像属性,并将该样式应用于按钮。
Microsoft Expression Blend将通过几个简单的步骤帮助您完成此操作。

您必须为按钮创建样式。为每个可视状态更改按钮的属性。如设置不同状态(如按下、正常等)的背景图像属性,并将该样式应用于按钮。
Microsoft Expression Blend将通过几个简单的步骤帮助您完成此操作。

您应该使用Expression Blend编辑按钮的样式。例如,当按钮处于按下状态时,您可以编辑背景或边框笔刷。

您应该使用Expression Blend编辑按钮的样式。例如,您可以编辑背景或边框当按钮处于按下状态时刷牙。

此问题有一些现有线程:

  • 我按照@thongaduka建议的方式实现了这一点。检查下面的完整实现

    <StackPanel Height="auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="auto" >
        <StackPanel.Resources>
            <Style x:Key="ButtonTemplate_ok" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetProperty="Background" Storyboard.TargetName="hoverbutton">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_pressed.png"/>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused"/>
                                        <VisualState x:Name="Unfocused"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="hoverbutton">
                                    <Border.Background>
                                        <ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_unpressed.png"/>
                                    </Border.Background>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </StackPanel.Resources>
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" >
               <Button Style="{StaticResource ButtonTemplate_ok}"  Content="OK" HorizontalAlignment="Center" Margin="546,296,198,130" Name="button1" VerticalAlignment="Center" Click="button1_Click" Width="57" Height="53" BorderBrush="White" Foreground="Black"/>       
        </Grid>
    </StackPanel>
    

    此问题有一些现有线程:

  • 我按照@thongaduka建议的方式实现了这一点。检查下面的完整实现

    <StackPanel Height="auto" HorizontalAlignment="Left" Margin="0,0,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="auto" >
        <StackPanel.Resources>
            <Style x:Key="ButtonTemplate_ok" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetProperty="Background" Storyboard.TargetName="hoverbutton">
                                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_pressed.png"/>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused"/>
                                        <VisualState x:Name="Unfocused"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="hoverbutton">
                                    <Border.Background>
                                        <ImageBrush ImageSource="/StickGameSlX;component/Images/buttons/ok_unpressed.png"/>
                                    </Border.Background>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </StackPanel.Resources>
    
        <!--LayoutRoot is the root grid where all page content is placed-->
        <Grid x:Name="LayoutRoot" >
               <Button Style="{StaticResource ButtonTemplate_ok}"  Content="OK" HorizontalAlignment="Center" Margin="546,296,198,130" Name="button1" VerticalAlignment="Center" Click="button1_Click" Width="57" Height="53" BorderBrush="White" Foreground="Black"/>       
        </Grid>
    </StackPanel>
    

    将按钮的ClickMode设置为按下将禁用该效果

    <Style TargetType="Button">
    <Setter Property="ClickMode" Value="Press"/>
    </Style>
    

    将按钮的ClickMode设置为按下将禁用该效果

    <Style TargetType="Button">
    <Setter Property="ClickMode" Value="Press"/>
    </Style>
    
    
    
    谢谢您的回复。但是我在VisualStudio中没有这样的选项吗?谢谢你的回复。但是我在VisualStudio中没有这样的选项吗?谢谢你的回复。但是我在VisualStudio中就没有这样的选项吗?如果你擅长用xaml编码,你可以用VS itslef来完成。Belnd是这类任务的工具。谢谢你的回复。但是我在VisualStudio中就没有这样的选项吗?如果你擅长用xaml编码,你可以用VS itslef来完成。Belnd是执行此类任务的工具。