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>
当我将所选值访问组合框中的方法时,它只显示
system.windows.Controls.comboboxitem:12
它没有设置该值.. 帮帮我PLEASE
答案 0 :(得分:1)
SelectedValuePath="Percentage"
尝试删除所有ComboBoxItem声明,从ViewModel公开以下属性并绑定到它ItemsSource={Binding Items}
public List<int> Items
{
get { return Enumerable.Range(1, 100).ToList(); }
}