0

所以我几个月前才开始使用 wpf,现在我想从组合框获取用户输入并将其绑定到两个变量,这样当 selectedItem 更改时,这两个变量也将反映更改。

我现在面临的错误是:

System.Windows.Data 警告:40:BindingExpression 路径错误:在“对象”“ObjectDataProvider”(HashCode=22018304)上找不到“_institution”属性。绑定表达式:路径=_机构;DataItem='ObjectDataProvider' (HashCode=22018304); 目标元素是'ComboBox'(名称='institutionCB');目标属性是“SelectedItem”(类型“对象”)

我不知道它在说什么。

<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>
4

0 回答 0