3

我有一个ToggleButton定义,如:

<ToggleButton Name="tbPinned"  Grid.Row="0" Grid.Column="3" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="1,0,0,-5" Height="30" Width="30" IsChecked="True" Checked="tbPinned_Checked" Unchecked="tbPinned_Unchecked" >
            <Image Source="/some_image.png" Stretch="Fill" />
         </ToggleButton>

但是,我只想让按钮成为图像,而不是按钮上的图像。如果我使用的是普通的Button,我会Style="{DynamicResource NoChromeButton}"在开始ToggleButton标签中执行类似的操作。但这不起作用。

我怎样才能模仿整个NoChromeButton事情ToggleButton

编辑:编辑以包括我如何使用常规Buttons:

<Button Style="{DynamicResource NoChromeButton}" Height="17" Margin="0,0,30,0" Name="btnMinimize" VerticalAlignment="Top" Grid.Column="1" Click="btnMinimize_Click" HorizontalAlignment="Right" Width="27" Padding="0" Visibility="Visible">
            <Image Source="/some_image.png" Stretch="None"  />
        </Button>
4

2 回答 2

9

只需将其复制/粘贴到新的 WPF 项目中即可。

   <Window x:Class="SOChromeButton.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="Chromeless" TargetType="{x:Type ToggleButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Border BorderThickness="0" Width="54" Height="54">
                            <ContentPresenter/>
                        </Border>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ToggleButton Style="{StaticResource Chromeless}" Name="tbPinned"  Grid.Row="0" Grid.Column="0" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10,0,0,0"  IsChecked="True" >
            <Image Source="C:\Temp\info.png"></Image>
        </ToggleButton>
    </Grid> </Window>
于 2013-11-01T14:42:46.530 回答
0

这会吗?

<ToggleButton Name="tbPinned"  Grid.Row="0" Grid.Column="3" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="1,0,0,-5" Height="30" Width="30" IsChecked="True" Checked="tbPinned_Checked" Unchecked="tbPinned_Unchecked" 
BorderThickness="0" Background="Transparent">
            <Image Source="/some_image.png" Stretch="Fill" />
</ToggleButton>
于 2013-10-31T21:55:46.793 回答