ComboBox的xaml绑定和后台代码绑定,求帮助??
xaml中:
<ComboBox SelectedValue="{Binding DepId}" SelectedValuePath="Id" DisplayMemberPath="Name"/>
后台代码: comboBox1.ItemsSource = DepartmentDAL.GetAll();
这样是成功的!
但是<ComboBox />不在xaml中绑定,完全在后台的话:
comboBox1.ItemsSource = DepartmentDAL.GetAll();
comboBox1.SelectedValue = "DepId";
comboBox1.DisplayMemberPath = "Name";
comboBox1.SelectedValuePath = "Id";
就会出现FormatException
GUID 应包含带 4 个短划线的 32 位数(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。错误!!
求解?????
binding
C#
------解决方案--------------------你最少得给ComboBox数据呀<ComboBox ItemsSource="{Binding}"/>
------解决方案-------------------- comboBox1.SelectedValue = DepartmentDAL.GetAll().DepId;
comboBox1.DisplayMemberPath = "Name";
comboBox1.SelectedValuePath = "Id";
comboBox1.ItemsSource = DepartmentDAL.GetAll();
交换下位置