wpf组合框模板所选项目显示不正确
下面是我的combobox模板。外观很好,装订也很好。但是,当我在列表中选择一个项目时(所选项目没有正确显示在框中),我会得到一个长字符串值(即:common.Dto.CityDto),它实际上是我为了绑定列表而定位的Dto的文件位置。奇怪的 谢谢wpf组合框模板所选项目显示不正确,wpf,templates,Wpf,Templates,下面是我的combobox模板。外观很好,装订也很好。但是,当我在列表中选择一个项目时(所选项目没有正确显示在框中),我会得到一个长字符串值(即:common.Dto.CityDto),它实际上是我为了绑定列表而定位的Dto的文件位置。奇怪的 谢谢 您忘记设置ContentPresenter的ContentTemplateSelector属性: <ContentPresenter ContentTemplateSelector="{TemplateBinding ItemTemplateS
您忘记设置
ContentPresenter
的ContentTemplateSelector
属性:
<ContentPresenter ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
模板在哪里?与模板无关;将DisplayName设置为要在dot objectGCamel中显示的属性-我在组合框中有这样的设置:SelectedValue=“{Binding Model.CityId,UpdateSourceTrigger=PropertyChanged}”SelectedValuePath=“Id”DisplayMemberPath=“display”我假设问题出在控件模板的内容演示器中。我希望它显示所选项目-它在下拉列表中的显示方式??
<ContentPresenter ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>