【问题标题】:How to Bind the Image Source according the selected item?如何根据选中项绑定图片源?
【发布时间】:2013-08-11 09:57:01
【问题描述】:
如何根据列表框中的选中项绑定图像源,该列表框中包含具有图像属性的项?
<Button Name="btn">
<Button.Header>
<StackPanel>
<Image name="img">
<StackPanel>
</Button.Header>
</Button>
【问题讨论】:
标签:
wpf
button
data-binding
listbox
【解决方案1】:
根据您提供的信息,我将按照以下方式进行操作
<Button Name="btn">
<Button.Header>
<StackPanel>
<Image name="img" Source="{Binding SelectedItem.Image, ElementName=myListBox}" />
<StackPanel>
</Button.Header>
</Button>
<ListBox x:Name="myListBox">
</ListBox>
【解决方案2】:
像这样设置绑定:
<Image name="img" Source="{Binding SelectedItem.Image, ElementName=myListBox}" />