相关疑难解决方法(0)

SelectedItem,SelectedValue和SelectedValuePath之间的区别

以下是有什么区别的:

所有这些依赖项属性都在Selector类中定义.我经常混淆SelectedItemSelectedValue,并SelectedValueSelectedValuePath.

我想知道它们之间的区别,并且当我们使用它们,尤其是SelectedValueSelectedValuePath.请用一些简单的例子解释它们的用法.

silverlight wpf xaml selectedvalue selecteditem

335
推荐指数
4
解决办法
23万
查看次数

WPF ComboBox SelectionChanged事件导致命令不触发

我有以下XAML,ComboBox其中具有代码隐藏SelectionChanged事件处理程序和ViewModel的另一个Command属性。我将SelectedIndex属性设置为0。现在,当我运行项目时,将调用代码隐藏处理程序,但Command不会执行。我想要的是Command应该SelectedIndex=0在视图第一次加载时执行。

<ComboBox Name="listComboBox" SelectionChanged="listComboBox_SelectionChanged" SelectedIndex="0" SelectedValuePath="Content" Margin="5,0" Height="35" Width="150" VerticalAlignment="Center" HorizontalAlignment="Left">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding ListTypeComboSelectionChangedCmd}" CommandParameter="{Binding ElementName=listComboBox, Path=SelectedValue}"/>
        </i:EventTrigger>
     </i:Interaction.Triggers>
     <ComboBoxItem Content="ItemOne" />
     <ComboBoxItem Content="ItemTwo" />
     <ComboBoxItem Content="ItemThree" />
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

更新资料

代码隐藏事件处理程序:

<ComboBox Name="listComboBox" SelectionChanged="listComboBox_SelectionChanged" SelectedIndex="0" SelectedValuePath="Content" Margin="5,0" Height="35" Width="150" VerticalAlignment="Center" HorizontalAlignment="Left">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding ListTypeComboSelectionChangedCmd}" CommandParameter="{Binding ElementName=listComboBox, Path=SelectedValue}"/>
        </i:EventTrigger>
     </i:Interaction.Triggers>
     <ComboBoxItem Content="ItemOne" />
     <ComboBoxItem Content="ItemTwo" />
     <ComboBoxItem Content="ItemThree" />
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

ICommand对象:

private void …
Run Code Online (Sandbox Code Playgroud)

wpf combobox mvvm

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

wpf ×2

combobox ×1

mvvm ×1

selecteditem ×1

selectedvalue ×1

silverlight ×1

xaml ×1