简体   繁体   English

XAML中的图像按钮样式问题

[英]Image button style issues in XAML

I have a XAML code as follows: 我有一个XAML代码如下:

<Button 
    x:Name="stopButton" 
    Click="Stop_Click" 
    IsEnabled="False" 
    HorizontalAlignment="Right" 
    Height="75" 
    Width="75" 
    Grid.Column="1" 
    Margin="0,15,60,0" 
    BorderBrush="{x:Null}" 
    Visibility="Collapsed" >
    <Button.Background>
        <ImageBrush ImageSource="Images/stop.png"/>
    </Button.Background>
</Button>

With stop.png being the following image 使用stop.png是以下图像

The button is enabled during an event in the app, and is pressed to stop media playback. 该按钮在应用程序中的事件期间启用,并按下以停止媒体播放。 When the button is pressed, it turns white as shown in the following image: 按下按钮时,它会变为白色,如下图所示: 正常,悬停和按压状态之间的比较

I understand this is due to some Button Style issue, and was wondering how I would go about making this work better for me as a button. 我知道这是由于一些Button Style问题,并且想知道如何让这个作为一个按钮更好地为我工作。

if this button is in AppBar Use predefined style for Stop button : 如果此按钮位于AppBar中使用预定义样式的“停止”按钮:

<Button Style="{StaticResource StopAppBarButtonStyle}" />

You just have to uncomment it in Common/StandardStyles.xaml (that file is included in project) 您只需在Common / StandardStyles.xaml中取消注释(该文件包含在项目中)

If button is not in AppBar you can set Segoe UI Symbol font and code for stop character : 如果按钮不在AppBar中,您可以设置Segoe UI Symbol字体和停止字符的代码:

<Button FontFamily="Segoe UI Symbol" Content="&#xE1B5;"/>

You can see symbols here : 你可以在这里看到符号:

http://blogs.msdn.com/b/mohamedg/archive/2012/10/12/useful-segoe-ui-symbols.aspx http://blogs.msdn.com/b/mohamedg/archive/2012/10/12/useful-segoe-ui-symbols.aspx

You have to create custom style for your button. 您必须为按钮创建自定义样式。 Set all the visual states as you want. 根据需要设置所有视觉状态。

Button styles and templates 按钮样式和模板

use visual states to change button style 使用视觉状态来改变按钮样式

                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="btnEffect">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="Red" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Pressed">
                 <Storyboard>

                  <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Text" Storyboard.TargetName="BackgroundGlyph">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="&#xE19A;" />
                    </ObjectAnimationUsingKeyFrames>
                 <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="btnEffect">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="Black" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Disabled">

              </VisualState>
            </VisualStateGroup>

          </VisualStateManager.VisualStateGroups>


          <StackPanel Name="btnEffect" Opacity="1"  Width="100" Height="100" Background="Gray" Canvas.ZIndex="100" >
              <TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" 
                         FontFamily="Segoe UI Symbol" FontSize="53.333" Margin="-4,-19,0,0" 
                         Foreground="White"
                         Canvas.ZIndex="150"
            />

          </StackPanel>

        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM