Friday, August 7, 2009

Finding objects under control template at backend C# in Silverlight 3.0

<Button x:Name="muthu" >

<Button.Template>

<ControlTemplate TargetType="Button">

<Rectangle x:Name="baserect" Fill="Black" Loaded="baserect_Loaded"/>

</ControlTemplate>

</Button.Template>

</Button>



We can get in backend by :

private Rectangle baserect;

private void baserect_Loaded(object sender, RoutedEventArgs e)

{

this.baserect = (Rectangle)sender;

}

2 comments:

Unknown said...

You forgot to add Loaded event

Rectangle x:Name="baserect" Fill="Black" Loaded="baserect_Loaded"

But after I figured this out - your article was very useful.

Thanks

Fmass(Futuremass) said...

Thanks! I updated the blog with the missing code :)