WPF ComboBox中的BitmapFrame

时间:2009-10-12 07:17:51

标签: wpf xaml binding combobox bitmapframe

我有一个对话框,允许用户选择自定义图标。加载的图标显示在用户进行选择的组合框中。这是组合框的XAML代码:

<ComboBox 
    Style="{DynamicResource IconComboBox}"
    ItemTemplate="{StaticResource IconTemplate}"
    ItemsSource="{Binding Icons,
        RelativeSource={RelativeSource FindAncestor, 
            AncestorType={x:Type UserControl}}}"
    SelectedItem="{Binding Icon}"
    />
  • 图标是一个返回 BitmapFrame 数组的属性。
  • 图标是当前所选的属性。

当前不起作用的是当我通过后面的代码设置Icon属性时(例如,当显示用户上次显示对话框时选择了哪个Icon)时,Combobox选择只是空白。好像我在调用OnPropertyChanged之前将属性设置为null。

我目前的理论是WPF无法比较BitmapFrames,因此当遍历列表时,它无法确定那里的任何图标“相等”,因此假设为null。

总之;在组合框中设置当前所选项目(即BitmapFrame)的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以在后面的代码中使用SelectedItem或SelectedIndex来设置当前选定的项目!