我正在使用以下代码:
private Dictionary<string, string> GetNumber { get; set; }
public ReportsLetterTra()
{
GetNumber = new Dictionary<string, string>
{
{"1", "First"},
{"2", "Second"}
};
InitializeComponent();
}
xml代码:
<ComboBox
DisplayMemberPath="value"
SelectedValuePath="key"
ItemsSource="{Binding ElementName=reportslettra,Path=GetNumber}"
SelectedIndex="0" Name="cmbFromNumber" />
为什么不将 GetNumber 绑定到 cmbFromNumber?!
更新 :
我在后面文件中的完整代码:
using System.Collections.Generic;
using System.Windows;
namespace WpfApplication20
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Dictionary<string, string> GetNumber { get; set; }
public Window1()
{
GetNumber = new Dictionary<string, string>
{
{"1", "First"},
{"2", "Second"}
};
InitializeComponent();
}
}
}
我完整的 xaml 代码:
<Window x:Class="WpfApplication20.Window1" Name="eportslettra"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid Height="26">
<ComboBox DisplayMemberPath="Value" SelectedValuePath="Key"
ItemsSource="{Binding ElementName=reportslettra,Path=GetNumber}"
SelectedIndex="0" Name="cmbFromNumber" />
</Grid>
</Window>
我哪里错了?为什么不将 GetNumber 绑定到 cmbFromNumber?!