0

您好,我在 WPF 中有组合框

<ComboBox Name="mcombo" SelectedValuePath="Key" >
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=dictionary}" />
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

我也有

Dictionary<string, string> dictionary = new Dictionary<string, string>();
        dictionary.Add("val", "valvalval"); 

我忘记了什么?在组合框中,没有数据!

4

1 回答 1

0

First of all dictionary should be property not variable.

then You should bind Dictionary to ItemsSource

<ComboBox Name="mcombo" SelectedValuePath="Key" ItemsSource="{Binding Dictionary}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Value}" /> /Dont bind dictionary here. makes no sense
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

hope this helps..

Thanks

于 2013-08-30T10:44:49.867 回答