【问题标题】:Get Currently Visible Hub Section for Windows Phone 8.1 / Windows 8.1获取适用于 Windows Phone 8.1 / Windows 8.1 的当前可见集线器部分
【发布时间】:2014-05-16 13:27:57
【问题描述】:

在 Windows 8.1/Windows Phone 8.1 的 Hub 控件上是否有可以绑定到的属性,以便我可以获取当前选定的 HubSection?通常对于 TabControl,将设置 SelectedIndex 属性。但是,对于 Hub 控件,这似乎不存在。

到目前为止,我能找到的唯一相关的属性是 SectionsInView 属性。但是它是只读的,不能通过 DataBinding 绑定。

【问题讨论】:

  • 你是怎么绑定的?它是一个向量。尽管我可以从 TextBloc 数据绑定到它

标签: c# windows windows-phone-8 windows-runtime windows-phone


【解决方案1】:

想办法解决这个问题,可惜没有原生属性。

所以我做的是:

        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);
                }
            }
        }

似乎有效,但仍需测试(让我知道)

【讨论】:

  • 忘了说 ControlHelper 是我做过的一个类,但是你会在网上找到很多按类型查找子控件的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-15
  • 2015-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多