我有一个绑定到类 SInstance 的属性 LogicalP 的 wpf 组合框。组合框的 ItemSource 是一个字典,其中包含 LogicalP 类型的项。
如果我将 SInstance 中的 LogicalP 设置为初始状态,则组合框文本字段显示为空。如果我选择下拉菜单,我所有的字典值都在那里。当我更改 SInstance 中的选择 LogicalP 时,会正确更新。如果我在 C# 中更改 Sinstance,则相应的组合框值不会反映下拉菜单中更新的 LogicalP。
我已经将绑定模式设置为双向,但没有运气。有什么想法吗?
我的 Xaml:
<UserControl.Resources>
<ObjectDataProvider x:Key="PList"
ObjectType="{x:Type src:MainWindow}"
MethodName="GetLogPList"/>
</UserControl.Resources>
<DataTemplate DataType="{x:Type src:SInstance}">
<Grid>
<ComboBox ItemsSource="{Binding Source={StaticResource PList}}"
DisplayMemberPath ="Value.Name"
SelectedValuePath="Value"
SelectedValue="{Binding Path=LogicalP,Mode=TwoWay}">
</ComboBox>
</Grid>
</DataTemplate>
我的C#:
public Dictionary<string, LogicalPType> LogPList { get; private set; }
public Dictionary<string, LogicalPType> GetLogPList()
{
return LogPList;
}
public class LogicalPType
{
public string Name { get; set; }
public string C { get; set; }
public string M { get; set; }
}
public class SInstance : INotifyPropertyChanged
{
private LogicalPType _LogicalP;
public string Name { get; set; }
public LogicalPType LogicalP
{
get { return _LogicalP; }
set
{
if (_LogicalP != value)
{
_LogicalP = value;
NotifyPropertyChanged("LogicalP");
}
}
}
#region INotifyPropertyChanged Members
#endregion
}