简体   繁体   English

如何使用Blend将图像绑定到按钮模板?

[英]How to bind an image to a button template using Blend?

In Microsoft Expression Blend, I have the following button template: 在Microsoft Expression Blend中,我具有以下按钮模板:

    <ControlTemplate x:Key="ImageBlueButton" TargetType="{x:Type Button}">
        <Grid x:Name="MainGrid" Width="75" Height="50">
            <Grid.RowDefinitions>
                <RowDefinition Height="0.5*"/>
                <RowDefinition Height="0.5*"/>
            </Grid.RowDefinitions>  
            <ContentPresenter x:Name="TextContent" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Grid.Row="1" d:LayoutOverrides="Width, Height"/>
            <Image x:Name="ButtonImage" Margin="0" Grid.RowSpan="1" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{TemplateBinding Content}"/>
        </Grid>         
    </ControlTemplate>

I manually edited the XAML to add the Source={TemplateBinding Content} property to the Image tag. 我手动编辑了XAML,将Source = {TemplateBinding Content}属性添加到Image标记。 My question is, how do I assign an image to a button object that's using this template inside Blend? 我的问题是,如何将图像分配给在Blend中使用此模板的按钮对象?

In Blend, I can see a Common Properties window with Content field in it, but changing it only updates the text on the button. 在Blend中,我可以看到一个Common Content窗口,其中包含Content字段,但是更改它只会更新按钮上的文本。 I'm guessing I need to use Custom Expression, to set both Text Content and Image content at the same time? 我猜我需要使用自定义表达式来同时设置文本内容和图像内容吗?

Looks like there's no way to set multiple Content properties inside a template (Text and Image). 似乎无法在模板(文本和图像)中设置多个Content属性。 I will have to create my own UserControl instead. 我将不得不创建自己的UserControl。 This question is similar to the one answered here . 这个问题类似于这里回答的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM