C# 设置组合框';s SelectedItem从列表框UWP到对象

C# 设置组合框';s SelectedItem从列表框UWP到对象,c#,uwp,C#,Uwp,我有一个列表视图,用于填充我的科目表: public class ChartOfAccounts { public int AccountCode { get; set; } public string AccountTitle { get; set; } public string Description { get; set; } public string SubCategory { get; set; } public string Categor

我有一个列表视图,用于填充我的科目表:

public class ChartOfAccounts
{
    public int AccountCode { get; set; }
    public string AccountTitle { get; set; }
    public string Description { get; set; }
    public string SubCategory { get; set; }
    public string Category { get; set; }
    public bool Active { get; set; }
}
通过此列表视图,我希望填充其他控件,如:

private void MainRadDataGrid_SelectionChanged(object sender, Telerik.UI.Xaml.Controls.Grid.DataGridSelectionChangedEventArgs e)
{
    RadDataGrid rdg = (RadDataGrid)sender;

    var SelectedCOA = (ChartOfAccounts)rdg.SelectedItem;

    if (rdg !=null && rdg.SelectedItems.Count > 0) {
        AccountCodeTextBox.Text = SelectedCOA.AccountCode.ToString();
        AccountTitleTextBox.Text = SelectedCOA.AccountTitle;
        DescriptionTextBox.Text = SelectedCOA.Description;
        CategoryComboBox.SelectedItem = SelectedCOA.Category;

        SubCategoryComboBox.SelectedItem = SelectedCOA.SubCategory;
    }
}
问题是,我无法将
类别
子类别
组合框设置为相关的
类别
子类别
。组合框仅显示
类别
子类别
单词,而不是实际选定的项目


有人能解释为什么这不起作用吗?

我想你的答案是:

CategoryComboBox.SelectedItem = Combox1.FindStringExact(SelectedCOA.Category.?) // ? = displayed cat name


您将什么设置为CategoryComboBox.ItemsSource?如果没有设置ItemsSource,则无法直接设置SelectedItem。另请参见关于如何正确选择项目的答案。
CategoryComboBox.SelectedIndex = CategoryComboBox.Items.IndexOf(SelectedCOA.Category.?);