I had a problem linking the selected value of the combo box embedded in the list view. I have no problem displaying items in a combo box. However, I wish I had a way to determine that the combo box should be displayed (from among the elements it contains) with the click of a button. I think there are a few posts on this subject, however I cannot get exactly what I want. Here is my code.
XAML:
<Grid> <StackPanel Orientation="Vertical"> <ListView x:Name="OptionsListView" ItemsSource="{Binding MyObjectCollection}"> <ListView.Resources> <DataTemplate x:Key="comboBoxTemplate"> <ComboBox Margin="0,3" x:Name="MyTypeComboBox" SelectedValue="{Binding Path=SelectedType, Mode=TwoWay}"> <ComboBoxItem Content="ABC"/> <ComboBoxItem Content="DEF"/> <ComboBoxItem Content="XYZ"/> </ComboBox> </DataTemplate> </ListView.Resources> <ListView.View> <GridView> <GridViewColumn Header="Text-Sample" Width="100"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Name}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Combo-Sample" Width="100" CellTemplate="{StaticResource comboBoxTemplate}" /> </GridView> </ListView.View> </ListView> <Button Click="Button_Click">Click Me!</Button> </StackPanel> </Grid>
C # code:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); OptionsListView.DataContext = this; } private void Button_Click(object sender, RoutedEventArgs e) {
I would be glad if someone helped me hack this.
Thanks Ram
source share