【发布时间】:2010-10-19 17:41:49
【问题描述】:
我有一个带有ItemTemplates 的ListBox 和一些数据绑定,包括一个图像。
ItemsSource 在代码隐藏中设置。一切都按预期工作,直到应用程序尝试通过更新绑定到图像源的对象成员来更改图像的源。我做错了什么?
这是 XAML:
<ListBox x:Name="myList" MouseDoubleClick="myList_MouseDoubleClick" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="DarkGray" BorderThickness="1">
<StackPanel Orientation="Horizontal" Width="100">
<Image Width="38" Height="38" Source="{Binding Path=icon}" />
<StackPanel Width="100">
<Label Content="{Binding Path=name}" />
<Label Content="{Binding Path=state}" />
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
部分代码隐藏:
在Window_Initialized:
myList.ItemsSource = myLineList;
在myList_MouseDoubleClick:
Line aLine = myList.SelectedItem as Line;
if (aLine != null) {
aLine.icon = "idle.jpg";
}
【问题讨论】: