Search code examples
c#mvvmlivecharts

Click on a chart and open the same chart in another window with MVVM?


I have a Window in XAML with some different charts. What I wanted to do is to click that chart and open another window that shows me the same chart and another elements added to the GUI, but I don´t know what I am looking to, I am not sure if MVVM would help me or shoukd I start looking for something else?


Solution

  • You are looking for input bindings:

    <ChartPart Background="Transparent">
      <ChartPart.InputBindings>
    
    
        <MouseBinding Command="{Binding ShowInAntoherView}"
                      CommandParameter="{Binding Path}"
                      Gesture="LeftDoubleClick""/>
    
      </ChartPart.InputBindings>
    

    (Background=Transparent is important, because if the background is null, control does not pass a check if it was clicked)

    This allows you invoke commands with parameters on pretty much all controls on a variety of possible user actions.

    Just pass a clicked chart viewModel to a command that will navigate to it - done.

    What a <ChartPart> is in your case depends on a library you use (in your case it is Livecharts), but it should not be a problem to figure out.