所以我几个月前刚开始使用wpf,现在我想从comboBox获取用户输入并将其绑定到两个变量,这样当selectedItem发生变化时,这两个变量也将反映出变化。
我现在面临的错误是:
System.Windows.Data警告:40:BindingExpression路径错误:'object'''ObjectDataProvider'(HashCode = 22018304)'上找不到'_institution'属性。 BindingExpression:路径= _institution; DataItem ='ObjectDataProvider'(HashCode = 22018304); target元素是'ComboBox'(Name ='institutionCB'); target属性是'SelectedItem'(类型'Object')
我不知道它说的是什么。
<Windows.Resources>
<ObjectDataProvider x:Key="institutionData" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Institutions"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="userInputData" ObjectType="{x:Type local:userInputData}">
<ObjectDataProvider.MethodParameters>
<sys:String>_institution</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="commonServiceModel" ObjectType="{x:Type local:ServiceCommonModel}">
<ObjectDataProvider.MethodParameters>
<sys:String>_institution</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<local:Converter x:Key="Converter"/>
</Window.Resources>
转换器在我的代码背后:
public class Converter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return new object[] { value, value };
}
}
这是我的组合框:
<ComboBox x:Name="institutionCB" HorizontalAlignment ="Left" VerticalAlignment="Top" Height="22" Width="51" Margin="5,27,0,0" Background="White"
ItemsSource="{Binding Source={StaticResource institutionData}}" Tag="Institution">
<ComboBox.SelectedItem>
<MultiBinding Converter="{StaticResource Converter}">
<Binding Source="{StaticResource userInputData}" Path="_institution" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
<Binding Source="{StaticResource commonServiceModel}" Path="_institution" BindsDirectlyToSource="True" Mode="OneWayToSource"/>
</MultiBinding>
</ComboBox.SelectedItem>
</ComboBox>