Reputation: 13
On Windows Phone how can I get the rectangle in the user interface (UI)?
<phone:LongListSelector x:Name="lst" ItemRealized="lst_ItemRealized">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid>
<Rectangle x:Name="rect"/>
<Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
This is the get section:
private void lst_ItemRealized(object sender, ItemRealizationEventArgs e)
{
//Rectangle r = get rectangle rect from the data template;
}
Upvotes: 1
Views: 127
Reputation: 9242
Actually your problem is different one. If you break it one more level you find that actually you have to get the UI element from LongListSelector
DataTemplate that is your Rectangle.
And if you tell this problem to our friend(google) you will find your ans on first link. I see How do I access a control inside a XAML DataTemplate? is exactly similar to yours.
According to solution you have to find the Control(Rectangle) in Visual tree of DataTemplate.
And if you notice in solution actually a name has been given to the control that has to find out. It is better this way because if you search the visual tree for some types e.g say Rectangle then you may have come across a situation in which multiple Rectangle are present in DataTemplate.
I didn't want to copy paste the same code so refer the link for code. Hope it will help you :)
Upvotes: 2