css - 如何添加wpf图像按钮?

标签 css wpf mvvm

您好,我正在使用 MVVM 开发 WPF 应用程序,我正在尝试将图像添加为按钮(如 Windows 8 起始页按钮)有没有办法让按钮仅显示为图像?我有一个我想单独用作按钮的图像,但我似乎无法让按钮边框消失并且按钮背景颜色变得透明。或以任何方式将图像用作按钮?帮帮我

<Button Style="{StaticResource RoundCorner}"  Grid.Column="4" Grid.Row="2" 
      x:Name="New" Cursor="Hand" FontWeight="ExtraBold" 
      Margin="10,22,102,5" Grid.RowSpan="4" Grid.ColumnSpan="2">

  <Image Source="pack://siteoforigin:,,,/Resources/NewIcon.png"
           RenderOptions.BitmapScalingMode="HighQuality" Width="145" Height="93"  />
</Button>

最佳答案

您可以将默认的 Button ControlTemplate 替换为普通的 Image 控件。试试这个:

<Button Click="Button_Click" Width="16" Height="16">
    <Button.Template>
        <ControlTemplate>
            <Image Stretch="None" 
Source="pack://application:,,,/AppName;component/FolderName/ImageName.png" />
        </ControlTemplate>
    </Button.Template>
</Button>

关于css - 如何添加wpf图像按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25846421/

相关文章:

html - 轮播指示器激活

css - 更改背景图像时,悬停时的颜色更改不起作用

c# - MVVMLight+MvvmDialogs 找到的程序集的 list 定义与程序集引用不匹配

mvvm - Freshmvvm 从后面的 Page 代码访问 PageModel

c# - 将数据从 WCF 绑定(bind)到 MVVM 客户端始终为空

css - Flexbox - 使用 flex-grow、shrink、basis 相对于字段增加标签

php - 换行符 php 和 html 不工作

WPF - 以 jpeg 格式保存 Canvas 的黑色背景

c# - 从我的 C# 程序的同一文件夹启动 .exe

c# - 绑定(bind)文本框 enter press to reactive command