慕慕森
你可以发挥一点创意来解决这个问题。假设您有一个宽度仅为 60 像素的组合框。因此,您希望组合项显示为完整的州名称和缩写,例如CA - California,但如果选择,您只需要缩写。CA。我声明一个类来代表一个状态,如下所示:public class State{ public string ShortName { get; set; } public string FullName { get; set; } private string _displayName; public string DisplayName { set { _displayName = value; } get { if (string.IsNullOrEmpty(_displayName)) return string.Format("{0} - {1}", ShortName, FullName); else return _displayName; } }}技巧是您用来DisplayName在组合框中显示项目。然后,在getof中DisplayName,如果它已经有值,则返回它,如果没有,则连接状态的短名称和全名称。然后,当您进行数据绑定时,您将拥有一个状态列表以及SelectedState,并且在该属性的设置器中,您将DisplayName设为ShortName。所以,我的XAML:<Grid> <ComboBox ItemsSource="{Binding States}" SelectedValue="{Binding SelectedState}" DisplayMemberPath="DisplayName" Name="CmbStates" Width="60" Height="32"/></Grid>然后,在我的代码中:public partial class MainWindow : Window, INotifyPropertyChanged{ public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private List<State> _states; public List<State> States { get { return _states; } set { _states = value; OnPropertyChanged("States"); } } private State _selectedState; public State SelectedState { get { return _selectedState; } set { _selectedState = value; SelectedState.DisplayName = SelectedState.ShortName; OnPropertyChanged("SelectedState"); } } public MainWindow() { InitializeComponent(); States = new List<State> { new State() { FullName = "California", ShortName = "CA" }, new State() { FullName = "New York", ShortName = "NY" }, new State() { FullName = "Oregon", ShortName = "OR" } }; DataContext = this; }}现在列表中应该有完整的串联名称:但只有选择时的缩写: