1
我有一个按钮,里面有图像。此按钮多次显示在数据网格上以显示行的状态。当用户单击该按钮时,它将该行上的基础对象的状态更改为启用或禁用。这里是按钮的样子:在使用转换器时重新绑定图像源?
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button CommandParameter="{Binding}" HorizontalAlignment="Center">
<Image Source="{Binding Converter={StaticResource EnableDisableConverter}}" Height="25" Width="25" />
</Button>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
转换器正确返回基于状态的正确的图像。问题是我已经切换到MVVM模型,我的代码更改图像将不再工作。我以前是这样的:
Image img = (Image)btn.Content;
if (c.Status == Administration.Web.ObjectStatus.Enabled) {
img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Images/enable-icon.png", UriKind.Relative));
} else {
img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Images/disable-icon.png", UriKind.Relative));
}
期间更改的状态的命令,我试着养了变化包含对象的属性,但它并不反映它的UI。如果我对屏幕进行了硬刷新,则状态会正确更改。目前情况下有没有办法重新塑造图像?
结束绑定到对象上的状态字段,并完美的工作。谢谢! – Josh 2011-03-10 15:35:54