【问题标题】:How to bind an image to a button template using Blend?如何使用 Blend 将图像绑定到按钮模板?
【发布时间】:2012-06-21 15:54:56
【问题描述】:

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

我手动编辑 XAML 以将 Source={TemplateBinding Content} 属性添加到 Image 标记。我的问题是,如何将图像分配给在 Blend 中使用此模板的按钮对象?

在 Blend 中,我可以看到一个带有 Content 字段的 Common Properties 窗口,但更改它只会更新按钮上的文本。我猜我需要使用自定义表达式来同时设置文本内容和图像内容?

【问题讨论】:

    标签: c# wpf blend


    【解决方案1】:

    看起来无法在模板内设置多个内容属性(文本和图像)。我将不得不创建自己的 UserControl。这个问题和here回答的问题类似。

    【讨论】:

      猜你喜欢
      • 2012-06-20
      • 2011-11-28
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2011-09-08
      相关资源
      最近更新 更多