簡體   English   中英

獲取Windows Phone 8.1 / Windows 8.1的當前可見集線器部分

[英]Get Currently Visible Hub Section for Windows Phone 8.1 / Windows 8.1

我可以在Windows 8.1 / Windows Phone 8.1的集線器控件上綁定一個屬性,以便獲得當前選擇的HubSection嗎? 通常對於TabControl,可以設置SelectedIndex屬性。 但是,對於集線器控件似乎並不存在。

到目前為止,我可以找到的唯一與此相關的屬性是SectionsInView屬性。 但是,它是只讀的,不能通過DataBinding綁定。

在此處輸入圖片說明

找到一種處理該問題的方法,但遺憾的是它沒有本機屬性。

所以我所做的是:

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

似乎可以工作但仍在測試(請告訴我)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM