如何显示预绑定组合框中的值并将其绑定到另一个组合框对象属性

时间:2019-05-24 12:24:31

标签: c# xaml mvvm combobox selecteditem

我有一个“子”组合框,它预先填充了以下属性-

 public KeyValuePair<int, string>[] _imageProcessorTypeItems = {
            new KeyValuePair<int, string>(0, "Face"),
            new KeyValuePair<int, string>(1, "Frame"),
            new KeyValuePair<int, string>(2, "Recognized")
        };

针对ComboBox的XAML

 <ComboBox Header="Type" x:Name="ImageProcessorType" 
    Grid.Row="0" Grid.Column="0" Width="400" HorizontalAlignment="Stretch" 
    ItemsSource="{Binding ImageProcessorTypeItems}" DisplayMemberPath="Value" 
    SelectedValuePath="Value"
    SelectedValue="{Binding Path=SelectedImageProcessorsValue , Mode=TwoWay}" />

我有一个主组合框,下面装有一个ImageProcessor类型类对象-

public int ProcessorId { get; set; }
public string ProcessorName { get; set; }
public ProcessorType processorType { get; set; }
public bool ProcessorEnabled { get; set; }
public int ProcessorMaxThroughput { get; set; }
public string ProcessorURI { get; set; }
public string ProcessorMaxRes { get; set; }
public ProcessorImageFormat processorImageFormat { get; set; }
public string ProcessorArgs { get; set; }
public string ProcessorImageSize { get; set; }

public enum ProcessorType
{
    Frame = 1,
    Face = 2,
    Recognized = 3
}

用于主ComBoBox的XAML-

 <ComboBox Header="Image Processors For Tenant" x:Name="SelectedImageProcessors" 
    Grid.Row="0" VerticalAlignment="Top" 
    IsEnabled="{Binding Path=EnableSelectedImageProcessors}" 
    HorizontalAlignment="Stretch"
    ItemsSource="{Binding Path=SelectedImageProcessorsItems}" 
    SelectedValuePath="ProcessorId"  SelectedValue="" 
    DisplayMemberPath="ProcessorName"
    SelectedItem="{Binding Path=SelectedImageProcessorsValue, Mode=TwoWay}" />

主组合框装有ImageProcessors对象,我正在从另一个代码中添加值-

我的要求是,当我选择ImageProcessor ProcessorName(它是DisplayMemberPath,并且该值作为对组合框的描述出现时)时,相应的ChildCombox也应根据{{ 1}}。

我正在玩SelectedItemSelectedValueSelectedValuePath,但无法正确处理。

0 个答案:

没有答案