C# 当前透视页面的可视元素
我正在使用C#、Silverlight、Visual Studio for Windows Phone 7 我感兴趣的是在透视过程中只获取当前显示在屏幕上的视觉元素。例如,我的pivot可以有5个PivotItems,但我只想获取每次flick之后显示的项目 现在,我可以从可视化树中获取整个数据透视,显然我可以选择一个特定的数据透视项。但是我希望能够在屏幕上只获取当前的轴。最终目标是获取元素在屏幕上的绝对位置,而不管当前的数据透视项是什么C# 当前透视页面的可视元素,c#,silverlight,windows-phone-7,pivot,visual-tree,C#,Silverlight,Windows Phone 7,Pivot,Visual Tree,我正在使用C#、Silverlight、Visual Studio for Windows Phone 7 我感兴趣的是在透视过程中只获取当前显示在屏幕上的视觉元素。例如,我的pivot可以有5个PivotItems,但我只想获取每次flick之后显示的项目 现在,我可以从可视化树中获取整个数据透视,显然我可以选择一个特定的数据透视项。但是我希望能够在屏幕上只获取当前的轴。最终目标是获取元素在屏幕上的绝对位置,而不管当前的数据透视项是什么 这可能吗?如果是,怎么做 轴上的SelectedItem
这可能吗?如果是,怎么做 轴上的
SelectedItem
和/或SelectedIndex
将返回当前可见的轴项目
用于说明我的观点的示例代码:
XAML:
这有用吗?谢谢!!是的,是的!!有趣的是,我目前正在通过一个LayoutUpdated事件触发我的方法,奇怪的是,它只被调用了几次。假设我有5个支点。LayoutUpdated在前3部电影中被触发,但以后不会再触发。知道这是为什么吗?我已经更改了我的代码,以便PivotSelectionChanged调用此方法。仍然很奇怪为什么LayoutUpdated在停止之前只调用了几次。为了将来参考,最好使用LoadedPivotItem事件,而不是PivotSelectionChanged,因为这样可以在完成数据透视后获取元素。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--Pivot Control-->
<controls:Pivot x:Name="SomePivot" Title="MY SAMPLE PIVOT">
<StackPanel>
<Button Content="Button 0"/>
<Button Content="Button 1"/>
<Button Content="Button 2"/>
<Button Content="Button 3"/>
<Button Content="Button 4"/>
<Button Content="Button 5"/>
<Button Content="Button 6"/>
<Button Content="Button 7"/>
<Button Content="Button 8"/>
<Button Content="Button 9"/>
<Button Content="Button 0"/>
<Button Content="Button 1"/>
<Button Content="Button 2"/>
<Button Content="Button 3"/>
<Button Content="Button 4"/>
<Button Content="Button 5"/>
<Button Content="Button 6"/>
<Button Content="Button 7"/>
<Button Content="Button 8"/>
<Button Content="Button 9"/>
</StackPanel>
</controls:PivotItem>
<controls:PivotItem Header="item2">
<Button Content="Button D" Name="B"/>
</controls:PivotItem>
<controls:PivotItem Header="item3">
<Button Content="Button D" Name="C"/>
</controls:PivotItem>
<controls:PivotItem Header="item4">
<Button Content="Button D" Name="D"/>
</controls:PivotItem>
</controls:Pivot>
<Button Grid.Row="1" Content="Get Current Pivot Item" Click="GetCurrentPivotItem"/>
</Grid>
private void GetCurrentPivotItem(object sender, RoutedEventArgs e)
{
PivotItem pivotItem = (PivotItem)SomePivot.SelectedItem;
Debug.WriteLine("Pivot Item : {0}", pivotItem.Header);
foreach (var element in VisualTreeHelper.FindElementsInHostCoordinates(new Rect(20, 0, 480, 700), pivotItem))
{
if (element is Button)
{
Debug.WriteLine("{0}", ((Button)element).Content);
}
}
}