【问题标题】:WPF Image Source BindingWPF 图像源绑定
【发布时间】: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";
}

【问题讨论】:

    标签: c# wpf image xaml binding


    【解决方案1】:

    您的“Line”类是否实现INotifyPropertyChanged,或使用依赖属性?它必须有某种方式来通知绑定“图标”属性的值已更改。

    【讨论】:

    • 非常感谢,就是这样。来自 mfc 和 adobe flash 编码,我认为这是理所当然的......
    猜你喜欢
    • 1970-01-01
    • 2013-01-11
    • 2017-10-09
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多