在XAML
我有:
<Window.Resources>
<DataTemplate x:Key="CastTemplate">
<DockPanel Width="Auto">
<Image Source="{Binding image}" Width="10" Height="10"/>
<TextBlock Text="{Binding name}"/>
<TextBlock Text="{Binding character}"/>
</DockPanel>
</DataTemplate>
<Window.Resources>
<Grid HorizontalAlignment="Center">
<ItemsControl ItemTemplate="{StaticResource CastTemplate}" ItemsSource="{Binding SelectedItem.castInfoWithPics}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3" Rows="2"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
binding
指向具有以下属性的对象列表:
public string name { get; set; }
public string character { get; set; }
public BitmapSource image { get; set; }
在我的ViewModel
中,我使用以下内容分配image
属性:
cast.image = loadBitmap(bitmap);
我正在使用此处所述的loadBitmap
功能:https://stackoverflow.com/a/1118557/2268507
我遇到的问题是,当我运行程序时,image
没有显示。但是会显示name
和character
属性。
我似乎也没有收到任何Binding
错误。有谁知道问题可能是什么?
答案 0 :(得分:1)
您确定在View模型中使用INotifyPropertyChanged
吗?
看起来您正在构造函数中设置其他属性,然后稍后设置您的Bitmap属性。在这种情况下,您必须提升PropertyChanged事件。