我有一个xaml视图,其中包含几个组合框。下面是我的组合框之一
<ComboBox x:Name="cboPT"
VerticalAlignment="Center"
Height="25"
Width="170"
DisplayMemberPath="Value"
HorizontalAlignment="Left"
Margin="5,0,5,0">
<ComboBox.ItemsSource>
<Binding Path="PT"
Mode="TwoWay" />
</ComboBox.ItemsSource>
<ComboBox.SelectedItem>
<Binding Path="SelectedPT"
Mode="TwoWay" />
</ComboBox.SelectedItem>
</ComboBox>
当我第一次访问该页面时显示绑定到它的值,但当我执行导致服务器端在表单上往返的任何操作时,它变为空白。
以下是我用于将数据绑定到组合框
的代码public Dictionary<string, string> PT
{
get { return _PT; }
set
{
_PT = value;
this.OnPropertyChanged("PT");
if (_PT.Count > 0 && (String.IsNullOrEmpty(SelectedPT.Value) || ResetPT))
{
ResetPT = false;
SelectedPT = _PT.FirstOrDefault();
}
else
{
this.OnPropertyChanged("SelectedPT");
}
}
}
public KeyValuePair<string, string> SelectedPT
{
get { return _SelectedPT; }
set
{
bool bIsNull = _SelectedPT.Equals(null);
if (bIsNull || !_SelectedPT.Equals(value))
{
_SelectedPT = value;
this.OnPropertyChanged("SelectedPT");
}
}
}