WPF组合框在样式化后显示对象类型
在我的项目中,我使用了一个ComboBox和我的自定义对象(如Employees)并使用DisplayMemberPath =“Description”。 这一切都像预期的完美。WPF组合框在样式化后显示对象类型
因为此应用程序旨在与触摸屏一起使用,所以我必须设计滚动条的样式并使其更宽,这意味着我必须为ScrolViewer创建一个新模板。这也相当不错。
当我需要为我需要的ComboBox创建一个新的ControlTemplate时,问题就出现了,因此我可以将ScrollViewerControlTemplate添加到ComboBox的ScrollViewer中。我使用Blend为我生成ControlTemplate,然后将ScrollViewerControlTemplate绑定到ComboBox ControlTemplate中的ScrollViewer。
优秀,唯一的问题是ComboBox在控件的下拉部分内显示正确的文本,但控件的ToggleButton部分显示对象类型是[NameSpace] .Employee。
我试着改变ContentPresenter但没有取得太大的成功。
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
任何帮助将不胜感激。
在您的ComboBox
模板中,该区域的内容应绑定到SelectionBoxItem
属性。所以,如果你使用的是ContentPresenter
显示选择:如果您使用的是ToggleButton
的内容区域
<ContentPresenter ContentSource="SelectionBoxItem" />
,你会做一些像这样:
<ToggleButton Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" />
嘿菲拉,对不起,我不能把这个标记为你的答案,因为我已经改变并解决了问题,并且无法测试你的建议。 – 2010-03-29 07:32:48
我没有时间来图确切地说问题是什么,但是我解决这个问题的方法是创建一个新窗口,将一个ComboBox拖到页面上并再次生成Xaml,并将其全部复制到App.Xaml文件中。 我想我错过了一些造成问题的风格。 – 2010-03-29 07:29:21