Button中的ComboBox,如何将Combobox的“SelectedItem”作为Button的CommandParameter传递?

问题描述 投票:1回答:1

我无法访问位于按钮内的Combobox的SelectedItem。我想将SelectedItem作为Button的CommandParameter传递给我的VM。在我的VM中,我使用MVVMLight的ICommand<T>

我究竟做错了什么?

<dx:SimpleButton Margin="0,5,0,5" MinWidth="160" Command="{Binding CreateNewSymbolCommand}" CommandParameter="{Binding ElementName=AssetClassInButton, Path=SelectedItem}">
            <dx:SimpleButton.ContentTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <TextBox Text="Choose Asset Class" Foreground="LightGreen" HorizontalAlignment="Center"/>
                        <dxe:ComboBoxEdit Name="AssetClassInButton" MinWidth="150" IsTextEditable="False" ItemsSource="{Binding Source={StaticResource AssetClassEnumValues}}"/>
                    </StackPanel>

                </DataTemplate>
            </dx:SimpleButton.ContentTemplate>
        </dx:SimpleButton>
c# wpf devexpress commandbinding
1个回答
3
投票

摆脱ContentTemplate \ DataTemplate - 您不需要它,因为您直接设置Button的内容而不是重复出现的元素的模板。

<dx:SimpleButton Margin="0,5,0,5" MinWidth="160" Command="{Binding CreateNewSymbolCommand}" CommandParameter="{Binding ElementName=AssetClassInButton, Path=SelectedItem}">
    <StackPanel Orientation="Vertical">
        <TextBox Text="Choose Asset Class" Foreground="LightGreen" HorizontalAlignment="Center"/>
        <dxe:ComboBoxEdit Name="AssetClassInButton" MinWidth="150" IsTextEditable="False" ItemsSource="{Binding Source={StaticResource AssetClassEnumValues}}"/>
    </StackPanel>
</dx:SimpleButton>
© www.soinside.com 2019 - 2024. All rights reserved.