我有一个由几个组合框组成的 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");
}
}
}