设置样式后显示对象类型的WPF组合框
在我的项目中,我将组合框与自定义对象(如Employees)一起使用,并使用DisplayMemberPath=“Description”。 这一切都像预期的那样完美 因为这个应用程序的目标是与触摸屏一起使用,所以我必须设计滚动条的样式并使其更宽,这意味着我必须为ScrolViewer创建一个新的模板。结果也相当不错 当我必须为ComboBox创建一个新的ControlTemplate时,问题就出现了,我需要它,以便将ScrollViewerControlTemplate添加到ComboBox的ScrollViewer中。我使用Blend为自己生成ControlTemplate,然后将ScrollViewerControlTemplate绑定到ComboBox ControlTemplate中的ScrollViewer 很好,唯一的问题是组合框在控件的下拉部分显示正确的文本,而控件的ToggleButton部分显示的对象类型是[NameSpace].Employee 我试着更换ContentPresenter,但没有成功设置样式后显示对象类型的WPF组合框,wpf,combobox,wpf-controls,Wpf,Combobox,Wpf Controls,在我的项目中,我将组合框与自定义对象(如Employees)一起使用,并使用DisplayMemberPath=“Description”。 这一切都像预期的那样完美 因为这个应用程序的目标是与触摸屏一起使用,所以我必须设计滚动条的样式并使其更宽,这意味着我必须为ScrolViewer创建一个新的模板。结果也相当不错 当我必须为ComboBox创建一个新的ControlTemplate时,问题就出现了,我需要它,以便将ScrollViewerControlTemplate添加到ComboBox的
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
非常感谢您的帮助。在您的
组合框
模板中,该区域的内容应绑定到SelectionBoxItem
属性。因此,如果您使用ContentPresenter
显示选择:
<ContentPresenter ContentSource="SelectionBoxItem" />
我没有时间去弄清楚到底是什么问题,但我解决问题的方法是创建一个新窗口,将一个组合框拖到页面上,再次生成Xaml,并将其全部复制到App.Xaml文件中。我想我遗漏了一些风格,这是造成问题的原因。嘿,伙计,对不起,我不能将此标记为您的答案,因为我已经更改并修复了问题,无法测试您的建议。
<ToggleButton Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" />