将图像数据绑定到内容呈现器 [英] Databind a Image to a content presenter

查看:74
本文介绍了将图像数据绑定到内容呈现器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我首先开始解释我的XAML体验很少。

Let me first start explaining that I have minimal XAML experience.

我有一个带有两个按钮的按钮contentpresenters(这可能吗?),一个用于文本,另一个用于图像。我如何绑定数据,以便显示所选图像。就像内容演示者显示您填写的文本行一样,Blend中的内容框

I've got a button with two contentpresenters (is this possible?), one for text and the other for an image. how can i data bind it so it will show the selected image. Just like the content presenter shows the line of text you fill in the content-box in Blend.

这是到目前为止的xaml:

This is the xaml so far:

< ContentPresenter x:Name =" contentPresenter_icon" ContentTemplate =" {TemplateBinding ContentTemplate}" Content = " how to" Margin =" 10,84,46,9" d:LayoutOverrides =" Horizo​​ntalAlignment">

        < ContentPresenter.DataContext>

          < BitmapImage />

        < / ContentPresenter .DataContext>&
       < / ContentPresenter>

<ContentPresenter x:Name="contentPresenter_icon" ContentTemplate="{TemplateBinding ContentTemplate}" Content="how to" Margin="10,84,46,9" d:LayoutOverrides="HorizontalAlignment">
        <ContentPresenter.DataContext>
         <BitmapImage/>
        </ContentPresenter.DataContext>
       </ContentPresenter>

非常感谢帮助。

推荐答案

您可以将多个控件放入内容值,它们只需要分组到一个容器中,如下所示:

You can put multiple controls into the Content value, they just have to be grouped into a container, like this:

<Button>
	<Grid>
		<Image Source="myimage.png"/>
		<TextBlock Text="The Text"/>
	</Grid>
</Button>


这篇关于将图像数据绑定到内容呈现器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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