我有ComboBox
自定义ItemTemplate
。带自定义项目模板文本的wpf组合框
<ComboBox Height="20" Width="200"
SelectedItem="{Binding Path=SelectedDesign}"
ItemsSource="{Binding Path=Designs}" HorizontalAlignment="Left"
ScrollViewer.CanContentScroll="False">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type formdesign:FormDesignContainer}">
<Rectangle Width="200" Height="100">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding Path=ImageThumb}" Stretch="Uniform" />
</Rectangle.Fill>
</Rectangle>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
这很好。但是,WPF会尝试将矩形绘制为组合框文本。我怎样才能为这个模板设置“文本”。所谓“文”我的意思是字符串或控制的,代表所选的项目,当项目被选中
换句话说写入组合框,我想这样做:
但现在我得到这个
您可以发布您放入ComboBox的物品类型代码吗?我想我还没有完全理解这个问题。 – Spontifixus
我的对象来自于Canvas – takayoshi
所以'Designs'属性是某种'IEnumerable