【发布时间】:2011-09-08 11:35:34
【问题描述】:
我正在尝试通过 XAML 将图像设置为按钮的背景。我有一个值转换器,可以转换图标路径并返回位图图像
public static BitmapImage GetImage(String name)
{
//return new BitmapImage from the location of the Path
}
我尝试直接将 Image 对象设置为 Button 的内容,但没有奏效。然后我尝试在 Button.BackGround 中设置 ImageBrush 标签的来源,但这仍然不起作用。
<Button Margin="3" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="0">
<Button.Background>
<ImageBrush ImageSource="{Binding Path=IconPath, Converter={StaticResource ImageSourceConverter}}" />
</Button.Background>
</Button>
这不是转换器的具体问题,因为相同的逻辑可以在我的树视图节点中显示图像。我在这里做错了什么?
【问题讨论】: