0
votes

I have a static collection:

<CollectionViewSource Source="{Binding Source={x:Static Application.Current}, Path=MarketDataListeners}" x:Key="ficServerMarketDataView"></CollectionViewSource>

which is a collection of type MarketDataListener. I have a ListView which is bound to this collection and a ContentControl which is bound to the selected item of this ListView. In the ContentControl I have a button that launches a child window (in code behind).

What Im doing is keeping track of the selected item in the main window like this:

private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  _selectedItem = ((sender as ListView).SelectedValue as MarketDataContainer);
}

and then when the button in the control control is clicked i execute:

private void ShowComponentsButton_Click(object sender, RoutedEventArgs e)
{
    var detailsWindow = new ComponentWindow(_selectedItem);
    var button = sender as Button;
    if (button == null) return;
    detailsWindow.Show();
}

This is the binding of the ContentControl:

        <ContentControl Name="Detail" Content="{Binding Source={StaticResource ficServerMarketDataView}}"
        ContentTemplate="{StaticResource detailsFicTemplate}" VerticalAlignment="Stretch" Foreground="Black" DockPanel.Dock="Bottom" />

Is it possible to remove the code tracking the selected item just launch the child window without a parameter? The child window's Title should be a property 'Name' on the currently selected MarketDataListener. Ideally the child window would not update when the selected item changes.

1

1 Answers

0
votes

Is it possible to remove the code tracking the selected item just launch the child window without a parameter?

I would strongly recommend you to show the details in the same window,
from user experience point of view it would be preferable. you can use a page or contentControl to show the detailsWindow data. in that case it would be easy to achieve what you are looking for, all you would have to do is bind the ContentControl.dataContext to listviewSelected item.

otherwise if you just have to by design create a new Window you could create a singelton ViewModel which would be bound to the ListViewSelected Item and each time you will open the DetailsWindow you would access this data.