BitmapFrame在WPF组合框 [英] BitmapFrame in WPF ComboBox

查看:497
本文介绍了BitmapFrame在WPF组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,让用户选择一个自定义图标。加载图标显示在用户在其中作出选择的组合框。这里是XAML code的组合框:

I have a dialog that lets the user pick a custom icon. Loaded icons are displayed in a combobox in which the user makes the selection. Here is the XAML code for the combobox:

<ComboBox 
	Style="{DynamicResource IconComboBox}"
	ItemTemplate="{StaticResource IconTemplate}"
	ItemsSource="{Binding Icons,
		RelativeSource={RelativeSource FindAncestor, 
			AncestorType={x:Type UserControl}}}"
	SelectedItem="{Binding Icon}"
	/>


  • 图标是用于返回 BitmapFrame 数组的属性。

  • 图标是当前选定的属性。

    • Icons is a property that returns an array of BitmapFrame.
    • Icon is a property for the currently selected.
    • 目前有什么不工作是,当我通过code后面设置图标属性(例如,当显示哪个图标,用户选择了最后一次是所示的对话框),组合框选择只是空白。我仿佛调用OnPropertyChanged之前设置该属性为null。

      What currently doesnt work is that when I through the code behind set the Icon property (for example, when displaying which Icon the user picked the last time the dialog was shown), the Combobox selection is just blank. As if I had set the property to null before calling OnPropertyChanged.

      我目前的理论是,WPF无法比拟BitmapFrames,所以在列表中行走时,它不能确定任何的图标有平等,因而假定空。

      My current theory is that WPF cannot compare BitmapFrames, so when walking through the list it fails to determine any of the icons there the "equal" and thus assumes null.

      在短;什么是落后,通过设置当前选定的项目,这是一个BitmapFrame,在组合框中code的最佳方式?

      In short; what is the best way to through code behind set the currently selected item, which is a BitmapFrame, in a combobox?

      推荐答案

      您可以在code使用的SelectedItem或SelectedIndex的背后,设置当前选择的项目!

      You can use SelectedItem or SelectedIndex in the code behind to set the currently selected item!

      这篇关于BitmapFrame在WPF组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆