WPF 按钮内容显示图片或者图标,Path

XML 复制代码
<telerik:RadButton
    Name="btn_Reset"
    Grid.Column="1"
    Margin="2"
    FontSize="15">
    <Grid Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="1.3*" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Path
            Width="20"
            Height="20"
            Margin="1"
            Data="{StaticResource ResetFlowGeometry}"
            Fill="{telerik:VisualStudio2019Resource ResourceKey=IconBrush}"
            Stretch="Uniform" />
        <ContentPresenter Grid.Row="1" Content="复位" />
    </Grid>
</telerik:RadButton>

path可以换成image就可以显示图片了。

此种方法只是简单替换 Button 的内容为 Image,未涉及模板(ControlTemplate或DataTemplate)

在需要保持第三方原有样式时候非常好用

如果Path不显示,试一下: Stretch="Uniform"

相关推荐
CoderIsArt11 小时前
C# WPF常用调试工具汇总
开发语言·c#·wpf
凉、介17 小时前
SylixOS 下的消息队列
linux·wpf·sylixos
Magnum Lehar17 小时前
wpf3d游戏引擎ProjectLayoutView实现
游戏引擎·wpf
摆烂的少年17 小时前
WPF中自定义DataGrid表格后,修改选中行的字体颜色或背景图
wpf
CoderIsArt17 小时前
WPF调试三种工具介绍:Live Visual Tree、Live Property Explorer与Snoop
wpf
甄天17 小时前
WPF Style样式 全局样式资源字典
c#·wpf
GalaxyPokemon2 天前
RPC - 服务注册与发现模块
wpf
FuckPatience2 天前
WPF 的RenderTransform使图标旋转180°
wpf
甄天3 天前
WPF数据绑定
c#·wpf
Magnum Lehar3 天前
wpf游戏引擎主界面实现3
ui·游戏引擎·wpf