这个问题可能已经在某个地方得到了回答,但我不知道该怎么表达这个问题。
是否只有XAML才能创建一个非绑定的WPF ComboBox来显示实际的SelectedItem (或SelectedValue)而不是"{System.Windows.Controls.ComboBoxItem: item 1}"?现在,selectedItem (或SelectedValue)需要在冒号处拆分字符串,然后从字符串中移除最后一个大括号。
有没有一种不用显式代码就能做到这一点的方法?
<ComboBox x:Name="cboTilePattern" Height="22" Width="200" Margin="0,0,20,0" >
<ComboBoxItem IsSelected="True">Square: Quarter Turn</ComboBoxItem>
<ComboBoxItem>Square: Monolithic Horizontal</ComboBoxItem>
<ComboBoxItem>Square: Monolithic Vertical</ComboBoxItem>
<ComboBoxItem>Rectangle: Chevron</ComboBoxItem>
<ComboBoxItem>Rectangle: Brick Horizontal</ComboBoxItem>
<ComboBoxItem>Rectangle: Brick Horizontal Flip</ComboBoxItem>
<ComboBoxItem>Rectangle: Brick Vertical</ComboBoxItem>
<ComboBoxItem>Rectangle: Brick Vertical Flip</ComboBoxItem>
<ComboBoxItem>Rectangle: Monolithic Horizontal</ComboBoxItem>
<ComboBoxItem>Rectangle: Monolithic Vertical</ComboBoxItem>
<ComboBoxItem>2 Squares: Checkerboard</ComboBoxItem>
<ComboBoxItem>2 Squares: Quarterturn Checkerboard</ComboBoxItem>
</ComboBox>发布于 2013-11-22 23:21:15
一种很好的技术是将SelectedValuePath设置为Content或Tag。例:
<StackPanel>
<ComboBox x:Name="combo" SelectedValuePath="Content">
<ComboBoxItem Content="item 1" />
<ComboBoxItem Content="item 2" />
</ComboBox>
<TextBlock Text="{Binding ElementName=combo,Path=SelectedValue}" />
</StackPanel>https://stackoverflow.com/questions/20156263
复制相似问题