将图像集成在带有样式的按钮中 [英] To integrate an image in a button with a style

查看:68
本文介绍了将图像集成在带有样式的按钮中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我想在背景按钮中集成一个图像定义在ressource dictionnary中。这个按钮有一个风格。当按钮没有样式时,我的图像出现。一旦我按下我的按钮样式,图像就不再出现了。



我不明白我的错误。你能帮助我吗?



这是源代码对于我的按钮样式:

Hi, everybody.

I want integrated a image define in ressource dictionnary in background button. This button has a style. When the button hasn''t style, my image appears. As soon as I put my button style, the image no longer appears.

I don"t understand my error. Can you help me?

Here is a source code for my button style :

<Style x:Key="CtrlButton" TargetType="{x:Type Button}">

        <Setter Property="FontFamily"  Value="Myriad Pro" />
        <Setter Property="FontSize"  Value="14" />        
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Width" Value="90" />
        <Setter Property="Margin" Value="10,20,10,0" /> 
        <Setter Property="Template">
            <Setter.Value>
                
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border   x:Name="ButtonBorder" 

                              CornerRadius="10,10,10,10" 

                              BorderThickness="4,4,4,4" 

                              removed="#00000000"

                              BorderBrush="#FF8F8F8F"

                              RenderTransformOrigin="0.5,0.5"

                    >
                    <ContentPresenter x:Name="ButtonContentPresenter"

                             VerticalAlignment="Bottom"  

                             HorizontalAlignment="Center"

                    />  
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="RenderTransform" TargetName="ButtonBorder">
                                <Setter.Value>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="0.9" ScaleY="0.9"/>
                                    </TransformGroup>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
                
            </Setter.Value>
        </Setter>
    </Style>





这是我的按钮的源代码:



Here is a source code for my button:

<Button  Content ="Close" Style="{StaticResource CtrlButton}" Name="btnClose"  Height="96" Width="96" HorizontalAlignment="Right"  Click="btnClose_Click" Margin="0,20,10,0">
                <Button.Background>
                    <VisualBrush Visual="{StaticResource Close}" >
                    </VisualBrush>
                </Button.Background>
            </Button>





感谢您的帮助。

最佳。



Thanks for your help.
best regard.

推荐答案

肯尼斯是正确的,你的风格覆盖在原始背景的上面



我不是确定你需要哪一个,但如果你强迫他们的背景来自父母那么它应该解决问题。

Kenneth is correct, your Style overlays ontop of the original background

I''m not sure if which of these you need but if you force their background to be from the parent then it should resolve the issue.
<border x:name="ButtonBorder" xmlns:x="#unknown">
                              CornerRadius="10,10,10,10" 
                              BorderThickness="4,4,4,4" 
                              removed="#00000000"
                              BorderBrush=" #FF8F8F8F" 
                              RenderTransformOrigin="0.5,0.5"
Background="{TemplateBinding Background}"
                    ></border>






or

                  <contentpresenter x:name="ButtonContentPresenter" xmlns:x="#unknown">
                             VerticalAlignment="Bottom"  
                             HorizontalAlignment="Center"
Background="{TemplateBinding Background}"
                    />  </contentpresenter>





您不需要更改按钮XAML,只需更改控件模板。



You shouldn''t need to change the button XAML, just the control template.


这篇关于将图像集成在带有样式的按钮中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆