Togglebutton内容在WPF中的图像更改

时间:2014-07-25 07:55:57

标签: c# wpf togglebutton

我在wpf中有使用 ToggleButton 的代码。

<Grid>
        <ToggleButton x:Name="pinButton" VerticalAlignment="Center" Width="auto" MaxWidth="26" Height="26"
                                          Background="{DynamicResource MyBorderBlueGradientBrush}" Focusable="False"
                                          DockPanel.Dock="Right"  BorderThickness="0" 
                                          OverridesDefaultStyle="False" BorderBrush="{DynamicResource MyBorderBlueGradientBrush}"  FontFamily="Webdings">
            <Label x:Name="Pinback" Background="{DynamicResource MyBorderBlueGradientBrush}" Width="26" Height="26" BorderBrush="{DynamicResource MyBorderBlueGradientBrush}">
                <Label x:Name="Pin"  FontSize="18" Foreground="White" Content="" Width="25" Height="25" Background="Black" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Label.RenderTransform>
                        <RotateTransform Angle="16" CenterX="29" CenterY="0"></RotateTransform>
                    </Label.RenderTransform>
                </Label>
            </Label>
        </ToggleButton>

    </Grid>

当我运行此代码时,我得到了这个窗口。

enter image description here

所以我的问题是“内容如何变成图片图片”。当我更改其在其他图片中转换的内容时。

1 个答案:

答案 0 :(得分:1)

该针脚来自XAML中Webdings FontFamily的字符:

<Label x:Name="Pin" FontSize="18" Foreground="White" Content="" Width="25" 
    Height="25" Background="Black" HorizontalAlignment="Center" 
    VerticalAlignment="Center" />

请注意Content属性...显然,您无法在此处看到该字符,因为该字体在网站上并不常见。另请注意FontFamily中声明的ToggleButton

<ToggleButton x:Name="pinButton" VerticalAlignment="Center" Width="auto" MaxWidth="26"
    Height="26" Background="Blue" Focusable="False" DockPanel.Dock="Right"  
    BorderThickness="0" OverridesDefaultStyle="False" BorderBrush="Blue"  
    FontFamily="Webdings">