[英]Get Currently Visible Hub Section for Windows Phone 8.1 / Windows 8.1
Is there a property that I can bind to on the Hub control in Windows 8.1 / Windows Phone 8.1 such that I can get the currently selected HubSection? 我可以在Windows 8.1 / Windows Phone 8.1的集线器控件上绑定一个属性,以便获得当前选择的HubSection吗? Normally for a TabControl, one would set the SelectedIndex property. 通常对于TabControl,可以设置SelectedIndex属性。 However this does not seem to exist for the Hub control. 但是,对于集线器控件似乎并不存在。
So far the only property I can find that is somewhat related is the SectionsInView property. 到目前为止,我可以找到的唯一与此相关的属性是SectionsInView属性。 However it is read only and it can't be bound to via DataBinding. 但是,它是只读的,不能通过DataBinding绑定。
Find a way to deal with that but a shame that there is no native property for it. 找到一种处理该问题的方法,但遗憾的是它没有本机属性。
So what I did is : 所以我所做的是:
private int CurrentSectionIndex = 0;
private HubSection CurrentSection
{
get { return this.Hub.SectionsInView[CurrentSectionIndex]; }
}
//Retrieve the ScrollViewer of the Hub control and handle the ViewChanged event of this ScrollViewer
public Page()
{
ScrollViewer sv = ControlHelper.GetChild<ScrollViewer>(this.Hub);
sv.ViewChanged += sv_ViewChanged;
}
//In the ViewChanged event handler body then calculate the index relative to the horizontal offset (means current position) of the ScrollViewer
void sv_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
if(!e.IsIntermediate)
{
double ho = ControlHelper.GetChild<ScrollViewer>(this.Hub).HorizontalOffset;
if (ho >= CurrentSection.ActualWidth - (this.ActualWidth - CurrentSection.ActualWidth))
{
CurrentSectionIndex = (int)((ho + (this.ActualWidth - CurrentSection.ActualWidth)) / CurrentSection.ActualWidth);
}
}
}
Seems to work but still to test (let me know) 似乎可以工作但仍在测试(请告诉我)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.