Bind ListView Control with Grid Resource: WPF

Grid resource provides a way to reuse the objects and values by other controllers, as we studied in previous posts. In this article we will bind the listview with Grid resource defined in XAML code:
<x:ArrayExtension Type="{ x:Type sys:String}" x:Key="placesSource">

This resource is the same in our recent article about listbox binding with grid resource. Write the following code in XAML to bind the above resource:
<ListView Name="listView" ItemsSource="{StaticResource placesSource}">

When we run this project then it will bind the above data with listview as shown in following image:

To get selected item from this listview, write following code in the selectionChanged event of the listview:
private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
string selectedValue = listView.SelectedItem.ToString();

Run the code and change the selection, a message box will display with the selected value.


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites