Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,679 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a simple test application were the selection in a ComboBox changes the content of an ObservableCollection which in turn is bound to a ListView. My problem is the ListView does not update on ComboBox Selection Changed. This is only intended as a simple test to identify a problem in a bigger project.
xaml
<ComboBox Grid.Column="0" Grid.Row="1" IsEditable="True" SelectionChanged="ComboBox_SelectionChanged">
<ComboBoxItem Content="Me"/>
<ComboBoxItem Content="Them"/>
</ComboBox>
<ScrollViewer Grid.Column="0" Grid.Row="6" Margin="0,0,0,-168">
<ListView ItemsSource="{Binding Person, Mode=OneWay}" Height="250">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewHeaderStyle}">
<GridViewColumn Header=" " >
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox FocusVisualStyle="{x:Null}" IsChecked="{Binding Include}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Name " DisplayMemberBinding="{Binding Path=.}"/>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
xaml Style
<Style x:Key="GridViewHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
CodeBehind
public ObservableCollection<String> Person { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
Person = new ObservableCollection<string>()
{
"Margaret","John","Stephen","Yvonne","Angela",
};
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Person.Clear();
Person = new ObservableCollection<string>()
{
"Cath","Maggie","Caitlin",
};
}
Any assistance would be appreciated.
For example, try this:
private void ComboBox_SelectionChanged( object sender, SelectionChangedEventArgs e )
{
Person.Clear( );
Person.Add( "Cath" );
Person.Add( "Maggie" );
Person.Add( "Caitlin" );
}