Answer the question
In order to leave comments, you need to log in
Why is SelectedItem not working in ListView for UWP app?
There is the following view:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DataContext="{d:DesignInstance local:RootViewModel}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Selected}" TextAlignment="Center"/>
<GridView Grid.Row="1"
SelectionMode="Single"
HorizontalAlignment="Center"
ItemsSource="{Binding Items}"
SelectedItem="{Binding Selected}" />
</Grid>
</Page>
public class RootViewModel : INotifyPropertyChanged
{
public IEnumerable<string> Items
{
get;
} = new[] { "1", "2", "3", };
string selected;
public string Selected
{
get
{
return this.selected;
}
set
{
this.selected = value;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Selected)));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question