Matt
Matt

Reputation: 7254

ComboBox inside Button, how to pass "SelectedItem" of Combobox as CommandParameter of Button?

I am not able to access SelectedItem of Combobox that resides inside a button. I want to pass the SelectedItem as CommandParameter of the Button to my VM. Inside my VM I use MVVMLight's ICommand<T>.

What am I doing wrong?

<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>

Upvotes: 1

Views: 819

Answers (1)

Martin Grundy
Martin Grundy

Reputation: 284

Get rid of the ContentTemplate\DataTemplate - you dont need it as you are setting the content of the Button directly and not the template of a reoccurring element.

<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>

Upvotes: 4

Related Questions