Click here to Skip to main content
16,016,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am writing a WPF application using MVVM. I have a list box which has multiple user controls loaded into it. When i click on a particular listbox item another control(Control1) will be loaded. I will close the control(Control1). Now when i click on the same user control(in listbox) again it does not load the control(Control1) again this is because the selectedItem value is fired because we selected the same item again. How can i make control to fire selected item again so that i can display the control again or is there any other way to resolve this.

My View Model code:

public TileControlViewModel SelectedItem
{
get { return _selectedItem; }
set
{
_selectedItem = value;
OnPropertyChanged("SelectedItem");
if (_selectedItem != null)
{
AddToLiveTile(_selectedItem.Key);
}

}
}

What I have tried:

I tried changing selected item to selected value but still it is not working.
Posted
Updated 11-Aug-16 22:56pm
v2
Comments
veeresh angadi 12-Aug-16 4:56am    
XAML code
<ListBox Name="lvDataBinding" SelectionMode="Single" ItemsSource="{Binding AllTiles}" SelectedItem="{Binding SelectedItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True">
<ListBox.ItemsPanel >
<itemspaneltemplate>
<wrappanel width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">


</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<datatemplate>
<custom:tilecontrol margin="10" datacontext="{Binding}">

</ListBox.ItemTemplate>
<ListBox>

1 solution

my XAML

<listbox name="lvDataBinding" selectionmode="Single" itemssource="{Binding AllTiles}" selecteditem="{Binding SelectedItem,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" issynchronizedwithcurrentitem="True">
<listbox.itemspanel> <itemspaneltemplate>
<wrappanel width="{Binding (FrameworkElement.ActualWidth), <br mode=" hold=" /> RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">


<listbox.itemtemplate> <datatemplate>
<custom:tilecontrol margin="10" datacontext="{Binding}" xmlns:custom="#unknown">

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900