0
votes

I have a listbox in my application which is populated with an observable collection and it shows the items correctly in the listbox. this listbox is in a panorama item page.when user taps on any item it will navigate to a new page.

But after user comes back to the previous page where listbox is displayed, the same item is already selected and here if user taps on it again nothing happens.is there a way to fix this so that the same item is not still selected by default after returning from its page?

the view is shown below:

<ListBox x:Name="lstSavedSource" ItemsSource="{Binding SavedDataSource}"
         SelectedItem="{Binding SelectedSource,Mode=TwoWay}"
         Grid.Row="1" Margin="0,10,0,0">
    <ListBox.ItemTemplate >
        <DataTemplate>                                  
            <TextBlock Foreground="White" FontSize="20"  Text="{Binding SavedSourceName}"  TextWrapping="Wrap" ></TextBlock>
            <TextBlock Foreground="White" FontSize="20"  Text="{Binding SavedSourceid}"  TextWrapping="Wrap"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

And the ViewModel has the following collection:

private ObservableCollection<DataSource> _SavedDataSource = new ObservableCollection<DataSource>();

public ObservableCollection<DataSource> SavedDataSource
{
    get
    {
        ObservableCollection<DataSource> savedDataSource = new ObservableCollection<DataSource>();
        savedDataSource = DataSource.GetSaved();              
        return savedDataSource;
    }
    set
    {
        this._SavedDataSource = value;
        RaisePropertyChanged("SavedDataSource");
    }
}
1
Could you be more specific, what should happen when returning to listbox page? - Max
I don't want it to be selected by default after returning from the page of the selected item. - krrishna

1 Answers

2
votes

Before navigating to the next page, set the SelectedIndex property to -1

listbx.SelectedIndex = -1;