Answered by:
how to get Grid view item position at a perticular position?

Question
-
Hi
I am displaying a list using GridView. now I have such type of situation is-
I want to take a rectangle over this grid view control and which have size of 1 gridView Item. now I need
on scrolling, when a gridview item is over come to that rectangle then I need that grid view item detail.
means I need that selected grid view item which comes over the rectangle.
If any problem in understanding, pls let me know.
sandeep chauhan
Friday, October 18, 2013 9:52 AM
Answers
-
Here's a proof-of-concept, you can refine it yourself (note that this is using Windows 8.1)
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid Width="500" Height="500" Background="Blue" HorizontalAlignment="Center" VerticalAlignment="Center"> <Rectangle x:Name="MyRectangle" Fill="Black" Stroke="Red" Width="400" Height="{Binding ElementName=MyLVI, Path=ActualHeight}" HorizontalAlignment="Left" VerticalAlignment="Center"/> <ScrollViewer Width="500" Height="500" HorizontalAlignment="Center" VerticalAlignment="Center" ViewChanging="ScrollViewer_ViewChanging"> <ListView x:Name="MyListView"> <ListViewItem x:Name="MyLVI">A</ListViewItem> <ListViewItem>B</ListViewItem> <ListViewItem>C</ListViewItem> <ListViewItem>D</ListViewItem> <ListViewItem>E</ListViewItem> <ListViewItem>F</ListViewItem> <ListViewItem>G</ListViewItem> <ListViewItem>H</ListViewItem> <ListViewItem>I</ListViewItem> <ListViewItem>J</ListViewItem> <ListViewItem>L</ListViewItem> <ListViewItem>M</ListViewItem> <ListViewItem>N</ListViewItem> <ListViewItem>O</ListViewItem> <ListViewItem>P</ListViewItem> <ListViewItem>Q</ListViewItem> <ListViewItem>R</ListViewItem> <ListViewItem>S</ListViewItem> <ListViewItem>T</ListViewItem> <ListViewItem>U</ListViewItem> <ListViewItem>V</ListViewItem> <ListViewItem>W</ListViewItem> <ListViewItem>X</ListViewItem> <ListViewItem>Y</ListViewItem> <ListViewItem>Z</ListViewItem> </ListView> </ScrollViewer> </Grid> <TextBlock FontSize="100" x:Name="DetailsView"/> </StackPanel>
private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e) { Point ListViewItemPoint; TopRectanglePoint = MyRectangle.TransformToVisual(MainGrid).TransformPoint(new Point(0, 0)); HalfWayRectanglePoint = new Point(TopRectanglePoint.X, TopRectanglePoint.Y + (MyRectangle.ActualHeight / 2)); foreach (ListViewItem LVI in MyListView.Items) { ListViewItemPoint = LVI.TransformToVisual(MainGrid).TransformPoint(new Point(0, 0)); if (ListViewItemPoint.Y > TopRectanglePoint.Y && ListViewItemPoint.Y < HalfWayRectanglePoint.Y) { DetailsView.Text = (String)LVI.Content; break; } } }
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.
- Edited by Matt SmallMicrosoft employee, Moderator Friday, October 18, 2013 2:14 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Tuesday, October 22, 2013 12:50 PM
Friday, October 18, 2013 2:13 PMModerator
All replies
-
Here's a proof-of-concept, you can refine it yourself (note that this is using Windows 8.1)
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid Width="500" Height="500" Background="Blue" HorizontalAlignment="Center" VerticalAlignment="Center"> <Rectangle x:Name="MyRectangle" Fill="Black" Stroke="Red" Width="400" Height="{Binding ElementName=MyLVI, Path=ActualHeight}" HorizontalAlignment="Left" VerticalAlignment="Center"/> <ScrollViewer Width="500" Height="500" HorizontalAlignment="Center" VerticalAlignment="Center" ViewChanging="ScrollViewer_ViewChanging"> <ListView x:Name="MyListView"> <ListViewItem x:Name="MyLVI">A</ListViewItem> <ListViewItem>B</ListViewItem> <ListViewItem>C</ListViewItem> <ListViewItem>D</ListViewItem> <ListViewItem>E</ListViewItem> <ListViewItem>F</ListViewItem> <ListViewItem>G</ListViewItem> <ListViewItem>H</ListViewItem> <ListViewItem>I</ListViewItem> <ListViewItem>J</ListViewItem> <ListViewItem>L</ListViewItem> <ListViewItem>M</ListViewItem> <ListViewItem>N</ListViewItem> <ListViewItem>O</ListViewItem> <ListViewItem>P</ListViewItem> <ListViewItem>Q</ListViewItem> <ListViewItem>R</ListViewItem> <ListViewItem>S</ListViewItem> <ListViewItem>T</ListViewItem> <ListViewItem>U</ListViewItem> <ListViewItem>V</ListViewItem> <ListViewItem>W</ListViewItem> <ListViewItem>X</ListViewItem> <ListViewItem>Y</ListViewItem> <ListViewItem>Z</ListViewItem> </ListView> </ScrollViewer> </Grid> <TextBlock FontSize="100" x:Name="DetailsView"/> </StackPanel>
private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e) { Point ListViewItemPoint; TopRectanglePoint = MyRectangle.TransformToVisual(MainGrid).TransformPoint(new Point(0, 0)); HalfWayRectanglePoint = new Point(TopRectanglePoint.X, TopRectanglePoint.Y + (MyRectangle.ActualHeight / 2)); foreach (ListViewItem LVI in MyListView.Items) { ListViewItemPoint = LVI.TransformToVisual(MainGrid).TransformPoint(new Point(0, 0)); if (ListViewItemPoint.Y > TopRectanglePoint.Y && ListViewItemPoint.Y < HalfWayRectanglePoint.Y) { DetailsView.Text = (String)LVI.Content; break; } } }
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.
- Edited by Matt SmallMicrosoft employee, Moderator Friday, October 18, 2013 2:14 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Tuesday, October 22, 2013 12:50 PM
Friday, October 18, 2013 2:13 PMModerator -
Hi
Its not working here in my windows 8. please provide sample for this.
TopRectanglePoint is missing when I used this code.
sandeep chauhan
Saturday, October 19, 2013 12:15 PM -
Hi Matt,
Thanks for reply,
Can you please describe following terms-
MainGrid (I think its a main grid which have xaml stackpanel)
TopRectanglePoint
HalfWayRectanglePoint
please quick response.
sandeep chauhan
Monday, October 21, 2013 10:51 AM -
TopRectanglePoint is the coordinate of the upper-left corner of the rectangle.
Halfwayrectanglepoint is the coordinate of the point which is on the left side of the rectangle, halfway between the upper-left correct and the bottom-left corner.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Tuesday, October 22, 2013 12:50 PMModerator