WPF Grid DropDown Example using the toolkit...

Feb 10, 2012 at 8:49 PM
Edited Feb 10, 2012 at 8:50 PM

I had a working model of grid dropdown and then swapped over to using the MVVMSimple Toolkit and now it does not work...  My thought is that the locator patter is preventing it from working...  can you provide an example on how you would implement a grid dropdown using the toolkit...                
                
                            

            
          
          
        
      
    
 

 

Feb 10, 2012 at 10:17 PM
Edited Feb 10, 2012 at 10:18 PM

Never mind i figured out my ancestor was originally a window as i was working in a window when I moved the view to a user control the user control became the ancestor not the window...

It may be just me but make sure your ancestor is a UserControl when your view is derived from a UserControl object...

Here is the example if it should benefit any one...

<DataGrid AutoGenerateColumns="False"
              ItemsSource="{Binding CompanyList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
              SelectedItem="{Binding SelectedCompany, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
              SelectionMode="Single" Grid.ColumnSpan="2">
            <DataGrid.Columns>
              <DataGridTextColumn Binding="{Binding CompanyID, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                  Header="ID" Width="auto"/>
              <DataGridTextColumn Binding="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                  Header="Name" Width="Auto"/>
              <DataGridTextColumn Binding="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                  Header="Description" Width="Auto"/>
                <DataGridComboBoxColumn Header="Type" Width="Auto"
                    SelectedValueBinding ="{Binding CompanyTypeID, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                    DisplayMemberPath="Type"  
                    SelectedValuePath="CompanyTypeID"
                    >
                    <DataGridComboBoxColumn.ElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CompanyTypeList, Mode=TwoWay}"/>
                        </Style>
                    </DataGridComboBoxColumn.ElementStyle>
                    <DataGridComboBoxColumn.EditingElementStyle>
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CompanyTypeList, Mode=TwoWay}"/>
                        </Style>
                    </DataGridComboBoxColumn.EditingElementStyle>
                </DataGridComboBoxColumn>
            </DataGrid.Columns>
          </DataGrid>