none
Dropdown Combobox with a Button MVVM RRS feed

  • Question

  • I can easily trigger a combobox to dropdown it's list if I use the code behind file.  That being said I've also got commands working so when I press a button, I fire a command function in my ModelView.  That being said, my ModelView has no access to the controls in the view (as it should be), so therefor I've got to trigger this in the view XAML code. So the closest thing I've found is this:

    <UserControl
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:View="clr-namespace:stackadvisors.projects.prtg_connectwise_integration_alpha"
                 xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="ConfigurationView" 
                 xmlns:t="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
                 mc:Ignorable="d" Height="409" Width="448">
       
        <UserControl.DataContext>
            <View:ConfigurationViewModel/>
        </UserControl.DataContext>
    
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="336"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <StackPanel  Background="#FFF4F3F3" Grid.Row="0">
                <Label x:Name="ConfigurationLabel" Content="CONFIGURATION" Margin="24,30,216,0" Foreground="#FFA19D9D" FontSize="30" FontFamily="Microsoft Yi Baiti" Height="36" VerticalAlignment="Top"/>
                <Label x:Name="TicketsLabel" Content="BOARD TO ACCEPT PRTG TICKETS" Margin="24,10,191,0" Foreground="#FFA19D9D" FontSize="15" FontFamily="Microsoft Yi Baiti" Height="24" VerticalAlignment="Top"/>
                <StackPanel  Background="#FFF4F3F3" Orientation="Horizontal" Margin="30,0" >
    
                    <ComboBox Name="BoardsComboBox" 
                              DataContext="{Binding Path=CurrentConfiguration, Mode=TwoWay}" 
                              ItemsSource="{Binding Path=Boards}" Height="30"  Width="357" VerticalAlignment="Top" ScrollViewer.CanContentScroll="True" >
                        <ComboBox.Style>
                            <Style TargetType="ComboBox">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=DropdownButton, Path=Click}" Value="True">
                                        <Setter Property="IsDropDownOpen" Value="True"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ComboBox.Style>
                    </ComboBox>
                    <Button Name="DropdownButton" Command="{Binding Path=DropDownCommand}" Content="V" Width="30" Height="30" Background="#FF0A980A" Foreground="#FFFCFFFC" />
                </StackPanel>
    
            </StackPanel>
            <Border Grid.Row="1" Background="#FFDBDADA">
                <Button Content="SAVE" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="74" Height="35" Background="#FF0A980A" Foreground="White" FontSize="17" FontFamily="Microsoft Yi Baiti" Margin="0,0,30,20" FontWeight="Bold"/>
            </Border>
        </Grid>
    
    </UserControl>
    

    As you can see I'm trying to style the combobox with a DataTrigger that fires when the button is clicked.  Can anyone see anything drastically wrong with this.  Am I on the right path? 

    I know it's a data trigger and not an event trigger but event triggers cause errors in those spots. I'm lost in the woods of WPF and MVVM.


    Taylor Deiaco Junior Developer Denver, CO

    Friday, July 22, 2016 7:30 PM

Answers