I am still new to MVVM/WPF, in my control, i create a grid and when user clicks on a row, i want it to do something. Currently, i have in my code executes some code on the view. Is this okay? since the view need to access data from the model, or how can i fully separate the view and the model?
Currently, i have this...
// our View Window
public partial class MarketPriceView : UserControl
{
public MarketPriceView()
{
InitializeComponent();
}
private void OHLCChart_Click(object sender, RoutedEventArgs e)
{
// MarketPriceGrid is our model
var cell = GridData.SelectedItem as MarketPriceGrid;
string prod = cell.ProdCode;
// do something with prod ...
}
}
and my XAML i have a datagrid
<DataGrid x:Name="GridData" ItemsSource="{Binding MarketPriceGrid}">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="OHLC Chart" Click="OHLCChart_Click"/>
</ContextMenu>
</DataGrid.ContextMenu>
...
</DataGrid>
Is this OK? Or how should i go about doing it without breaking the MVVM pattern?