I do not understand how to create a command to create a rectangle with interactive MVVM. Here is my code:
<Rectangle x:Name="Color01" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="10,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100" MouseDown="Color_MouseDown" /> <Rectangle x:Name="Color02" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="115,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/> <Rectangle x:Name="Color03" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="220,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/> <Rectangle x:Name="Color04" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="325,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/>
In my first rectangle, you see that I created the code behind the event. At first I don't know how to access my ViewModel from the code behind. Two is not really MVVM.
public partial class MainWindow : Window {
I just need to be able to change the simple boolean stored in the list stored in my viewModel when someone clicks on my rectangle. Why is it so complicated with MVVM?
c # wpf mvvm
Bastien vandamme
source share