【发布时间】:2021-08-31 10:50:25
【问题描述】:
请帮忙。我在 ResourceDictionary <DrawingImage x:Key="MyDrawingImage"> 中有一个 XAML 图像。如何使用 MVVM 将其绑定到
public class MyItemViewModel {
public string TextToDisplay { get; set; }
public string? ImageToDisplay { get; set;} ??????
}
问题是,从资源字典中绑定图像最优雅的方法是什么?
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Image Source="{Binding ImageToDisplay}" ???????? />
<TextBlock Grid.Row="1"
Text="{Binding TextToDisplay}"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
【问题讨论】: