关于ComboBox的绑定问题,取不到selectvalue值
继承ComboBox做了一个下拉,绑定值时出现加载取不到值的情况
弄了两个控件测试下
conectSql.GetDeptCompleted += (comsend, come) =>
{
cbDept.ItemsSource = new Stools().GetTree(come.Result.Where(q => q.CategoryID == 4).ToList(), "Name", "ID", "FParentID", "ID").ToList();
cbDept.DisplayMemberPath = "Name";
cbDept.SelectedValuePath = "ID";
};
cbSex.ItemsSource = new UserfulData().GetSex();
cbSex.DisplayMemberPath = "Name";
cbSex.SelectedValuePath = "ID";
conectSql.GetEmpCompleted += (comsend, come) =>
{
emp = come.Result.Where(q => q.ID.ToString() == sitem.ID).FirstOrDefault();
LayoutRoot.DataContext = emp;
};
<mycontrol:MyCombobox Grid.Column="1" Grid.Row="2" x:Name="cbDept" SelectedValue="{Binding FUnitID,Mode=TwoWay}" ></mycontrol:MyCombobox>
<mycontrol:MyCombobox Grid.Column="3" Grid.Row="2" x:Name="cbSex" SelectedValue="{Binding FSex,Mode=TwoWay}" ></mycontrol:MyCombobox>
protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
base.OnItemsChanged(e);
TextBox txtbox = GetTemplateChild("cbtext") as TextBox;
if (this.SelectedValue != null)
{
TreeViewInfo selectinfo = (this.ItemsSource as List<TreeViewInfo>).Where(q => q.ID == this.SelectedValue.ToString()).FirstOrDefault();
if (selectinfo != null)
txtbox.Text = selectinfo.Name;
}
}