Reputation: 1642
I am having the following code in my Xaml page of WPF project.
<Rectangle Name="myrect" MouseDown="myrect_MouseDown"/>
I have tried to set the fill property of the rectangle in code behind (i.e. in Xaml.cs) but the name myrect is not accessible from code behind.. what is am missing here.?
I need to change the Fill property when particular rectangle is selected, any ways to achieve it through property binding or styles?
Thanks
Upvotes: 1
Views: 172
Reputation: 3787
In mouse down event you have parameter object sender
.
This is your Rectangle
.
Something like that:
private void myrect_MouseDown(object sender, EventArgs e)
{
var rect = sender as Rectangle;
if(rect!=null)
{
//do it here...
}
}
Upvotes: 3