Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从WPF ToggleButton中删除默认chrome_C#_.net_Wpf_Button - Fatal编程技术网

C# 如何从WPF ToggleButton中删除默认chrome

C# 如何从WPF ToggleButton中删除默认chrome,c#,.net,wpf,button,C#,.net,Wpf,Button,我有一个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_Unchec

我有一个
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>
这样行吗

<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>

只需将其复制/粘贴到新的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>


通过从ToggleButon派生创建您自己的自定义控件。不,他可以使用样式@kmarks2,你能发布你的
NoChromeButton
风格吗?你应该能够创建一个非常相似的
ToggleButton
样式,但是你不能仅仅应用
按钮
样式,因为
ToggleButton
并不是从
Button
@HamletHakobyan派生出来的,这就是我本质上想要做的。可能是
样式中的一些标记
,但我不确定要修改什么才能模仿
无色按钮
样式。@MikeStrobel我刚刚插入了一个编辑来演示如何使用常规按钮。这是我尝试的第一件事。不幸的是,它似乎没有任何作用。可能是因为
ToggleButton
源于
CheckBox
。很好,它工作得很好。铬不见了。现在,根据我的原始代码片段,我在ToggleButton中设置了一个图像及其源代码。现在,该图像不再显示。我是否需要将我的ToggleButton图像移动到样式的ContentPresent中?谢谢更新答案。试试这个。让它在我面前运行,我可以看到图像。谢谢。标记为溶液的。
   <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>