C# WPF图像源绑定

C# WPF图像源绑定,c#,wpf,image,xaml,binding,C#,Wpf,Image,Xaml,Binding,我有一个带有ItemTemplates的ListBox,还有一些数据绑定,包括一个图像 ItemsSource在代码隐藏中设置。在应用程序尝试通过更新对象的成员(绑定到图像源)来更改图像源之前,一切都按预期进行。我做错了什么 以下是XAML: <ListBox x:Name="myList" MouseDoubleClick="myList_MouseDoubleClick" ScrollViewer.VerticalScrollBarVisibility="Disabled">

我有一个带有
ItemTemplate
s的
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>
myList\u鼠标双击中

Line aLine = myList.SelectedItem as Line;
if (aLine != null) {
  aLine.icon = "idle.jpg";
}

您的“Line”类是实现还是使用依赖属性?它必须有某种方式通知绑定“icon”属性的值已更改。

非常感谢,就是这样。来自mfc,也编写了AdobeFlash,我认为这是理所当然的。。。
Line aLine = myList.SelectedItem as Line;
if (aLine != null) {
  aLine.icon = "idle.jpg";
}