0

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

4

4 回答 4

3

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

<Style TargetType="Button">
<Setter Property="ClickMode" Value="Press"/>
</Style>
于 2012-09-10T04:32:27.013 回答
1

这个问题有一些现有的线程:

  1. 检查这个
  2. 或这个

我按照@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>
于 2012-07-03T05:26:29.700 回答
0

您必须为 button 创建一个样式。更改每个视觉状态的按钮属性。喜欢为不同状态设置背景图像属性,如按下、正常等。并为您的按钮应用该样式。Microsoft Expression Blend 将通过几个简单的步骤帮助您做到这一点。

于 2012-05-07T05:34:16.410 回答
0

您应该使用表达式混合来编辑按钮的样式。例如,当您的按钮处于按下状态时,您可以编辑背景或边框画笔。

于 2012-05-07T06:37:12.830 回答