【问题标题】:BitmapFrame in WPF ComboBoxWPF ComboBox 中的 BitmapFrame
【发布时间】:2009-10-12 07:17:51
【问题描述】:

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

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

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

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

简而言之;通过后面的代码在组合框中设置当前选定的项(即 BitmapFrame)的最佳方法是什么?

【问题讨论】:

    标签: wpf xaml binding combobox bitmapframe


    【解决方案1】:

    可以在后面的代码中使用SelectedItem或者SelectedIndex来设置当前选中的item!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      相关资源
      最近更新 更多