C# 访问组合框值以查看模型

C# 访问组合框值以查看模型,c#,wpf,mvvm,combobox,C#,Wpf,Mvvm,Combobox,Helo,我正在使用mvvm…我有一个组合框,这是xaml代码 <ComboBox Grid.Column="4" Grid.Row="3" Height="23" SelectedValue="{Binding Path=Percentage, Mode=TwoWay}" SelectedValuePath="Percentage" HorizontalAlignment="Left" Margin="18,7,0,0" Name="comboBox1" VerticalAlignm

Helo,我正在使用mvvm…我有一个组合框,这是xaml代码

 <ComboBox Grid.Column="4" Grid.Row="3" Height="23" SelectedValue="{Binding Path=Percentage, Mode=TwoWay}"  SelectedValuePath="Percentage" HorizontalAlignment="Left" Margin="18,7,0,0" Name="comboBox1" VerticalAlignment="Top" Width="144">
                <ComboBoxItem Content="12"></ComboBoxItem>
                <ComboBoxItem Content="13"></ComboBoxItem>
                <ComboBoxItem Content="14"></ComboBoxItem>
                <ComboBoxItem Content="15"></ComboBoxItem>
                <ComboBoxItem Content="16"></ComboBoxItem>
                <ComboBoxItem Content="17"></ComboBoxItem>
                <ComboBoxItem Content="18"></ComboBoxItem>
                <ComboBoxItem Content="19"></ComboBoxItem>
                <ComboBoxItem Content="20"></ComboBoxItem>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding PercentageChangedCommand}"
                                       CommandParameter="{Binding Percentage, ElementName=comboBox1}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ComboBox>
它没有设置该值。。 请帮帮我

  • 如果使用上面的代码段,combobox中的一个项就是ComboBoxItem,这就是为什么在百分比设置器中得到它
  • 首先,删除
    SelectedValuePath=“Percentage”
  • 尝试删除所有ComboBoxItem声明,从ViewModel中公开以下属性并绑定到它
    ItemsSource={Binding Items}

    公共列表项
    {
    get{return Enumerable.Range(1100.ToList();}
    }

  • 胜利!:)
    CommandParameter=“{Binding Percentage,ElementName=comboBox1}”
    -这会导致绑定错误,因为ComboBox上没有属性百分比。
    system.windows.Controls.comboboxitem:12