I have a C# and XAML project that involves a GridView bound to an ObservableCollection of Slides called myList. Slide has two properties of interest - a name and description. By default, the items in the GridView display the Name property, but I want a button to toggle between showing Name and showing Description.
Excerpt from Slide:
public class Slide : INotifyPropertyChanged {
private string _Name;
private string _Description;
public string Name {
get {
return this._Name;
} set {
//snipped for convenience: check that the property has changed and set it
}
}
public string Description {
get {
return this._Description;
} set {
//snipped for convenience: check that the property has changed and set it
}
}
/*etc...*/
}
The XAML looks something like this right now:
<GridView /*...*/ ItemsSource="{Binding myList}">
<GridView.ItemTemplate>
<DataTemplate>
<Grid /*...*/ >
<TextBlock /*...*/ Text="{Binding Name}" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
When the user clicks a button I want to programatically change the property bound to the Text field of the TextBlock in the DataTemplate, changing every item in the GridView. I know how to do it for an individual XAML Element, but I'm not sure how to do this for the dynamic content in a GridView. Any tips?
I snipped out a bunch of code that seemed superfluous, but let me know if there's any additional info you need.
Thanks!