예제 #1
0
        protected override void OnManipulationCompleted(ManipulationCompletedRoutedEventArgs e)
        {
            LoopItemsPickerPanel itemsPanel = e.Container as LoopItemsPickerPanel;

            if (itemsPanel == null)
            {
                return;
            }

            PickerSelectorItem selectorItem = itemsPanel.GetMiddleItem();

            if (selectorItem == null)
            {
                return;
            }

            DateTimeWrapper dateTimeWrapper = selectorItem.DataContext as DateTimeWrapper;

            if (dateTimeWrapper == null)
            {
                return;
            }

            this.Value = dateTimeWrapper.DateTime;
        }
예제 #2
0
        /// <summary>
        /// Update selected or not selected items state
        /// </summary>
        private void UpdateIsSelectedItems(DateTimeWrapper selectedValue)
        {
            if (this.Items == null || this.Items.Count <= 0)
            {
                return;
            }

            if (this.itemsPanel == null)
            {
                return;
            }

            if (selectedValue == null)
            {
                return;
            }

            foreach (PickerSelectorItem pickerSelectorItem in this.itemsPanel.Children)
            {
                DateTimeWrapper currentValue = (DateTimeWrapper)pickerSelectorItem.DataContext;
                pickerSelectorItem.IsSelected = selectedValue.DateTime == currentValue.DateTime;
                if (pickerSelectorItem.IsSelected)
                {
                    selectedPickerSelectorItem = pickerSelectorItem;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Maybe this method is Obsolet : TODO : Test obsoletence
        /// </summary>
        /// <param name="e"></param>
        protected override void OnManipulationCompleted(ManipulationCompletedRoutedEventArgs e)
        {
            PickerSelectorItem middleItem = this.itemsPanel.GetMiddleItem();

            if (middleItem == null)
            {
                return;
            }

            this.SelectedItem = middleItem.DataContext as DateTimeWrapper;

            base.OnManipulationCompleted(e);
        }
예제 #4
0
        /// <summary>
        /// Override of OnApplyTemplate
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.InitializationInProgress = true;

            primarySelector   = GetTemplateChild(PrimarySelectorName) as PickerSelector;
            secondarySelector = GetTemplateChild(SecondarySelectorName) as PickerSelector;
            tertiarySelector  = GetTemplateChild(TertiarySelectorName) as PickerSelector;

            // Create wrapper on current value
            var wrapper = new DateTimeWrapper(Value);

            // Init Selectors
            // Set Datasource
            if (primarySelector != null)
            {
                primarySelector.DatePicker     = this;
                primarySelector.YearDataSource = new YearDataSource();
                primarySelector.DataSourceType = DataSourceType.Year;
                primarySelector.CreateOrUpdateItems(wrapper.DateTime);
            }
            if (secondarySelector != null)
            {
                secondarySelector.DatePicker      = this;
                secondarySelector.MonthDataSource = new MonthDataSource();
                secondarySelector.DataSourceType  = DataSourceType.Month;
                secondarySelector.CreateOrUpdateItems(wrapper.DateTime);
            }

            if (tertiarySelector != null)
            {
                tertiarySelector.DatePicker     = this;
                tertiarySelector.DayDataSource  = new DayDataSource();
                tertiarySelector.DataSourceType = DataSourceType.Day;
                tertiarySelector.CreateOrUpdateItems(wrapper.DateTime);
            }

            this.ResetPickersOrder();

            this.InitializationInProgress = false;
        }
예제 #5
0
        /// <summary>
        /// On Tapped, make focus on the good PickerSelector
        /// </summary>
        protected override void OnTapped(TappedRoutedEventArgs e)
        {
            RefreshRect();

            Point point = e.GetPosition(this);

            FocusPickerSelector(point, FocusSourceType.Tap);

            PickerSelector selector = null;

            if (primarySelector != null && point.X > primarySelector.RectPosition.X &&
                point.X < (primarySelector.RectPosition.X + primarySelector.RectPosition.Width))
            {
                selector = primarySelector;
            }
            if (secondarySelector != null && point.X > secondarySelector.RectPosition.X &&
                point.X < (secondarySelector.RectPosition.X + secondarySelector.RectPosition.Width))
            {
                selector = secondarySelector;
            }
            if (tertiarySelector != null && point.X > tertiarySelector.RectPosition.X &&
                point.X < (tertiarySelector.RectPosition.X + tertiarySelector.RectPosition.Width))
            {
                selector = tertiarySelector;
            }

            if (selector != null)
            {
                DateTimeWrapper dateTimeWrapper = selector.SelectedItem;

                if (dateTimeWrapper == null)
                {
                    return;
                }

                this.Value = dateTimeWrapper.DateTime;
            }
        }
예제 #6
0
        /// <summary>
        /// Prepares the specified element to display the specified item.
        /// </summary>
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            if (DesignMode.DesignModeEnabled)
            {
                return;
            }

            itemsPanel = this.GetVisualDescendent <LoopItemsPickerPanel>();

            // get the item
            PickerSelectorItem loopListItem    = element as PickerSelectorItem;
            DateTimeWrapper    dateTimeWrapper = item as DateTimeWrapper;

            if (loopListItem == null || dateTimeWrapper == null)
            {
                return;
            }

            if (this.ItemTemplate == null)
            {
                return;
            }

            // load data templated
            var contentElement = this.ItemTemplate.LoadContent() as FrameworkElement;

            if (contentElement == null)
            {
                return;
            }
            // attach DataContext and Context to the item
            loopListItem.Style       = ItemContainerStyle;
            loopListItem.DataContext = item;
            loopListItem.Content     = contentElement;
            loopListItem.IsSelected  = dateTimeWrapper == this.SelectedItem;
            loopListItem.IsFocused   = this.IsFocused;
        }
예제 #7
0
        /// <summary>
        /// Update Items. Used for days
        /// </summary>
        internal void CreateOrUpdateItems(DateTime dateTime)
        {
            if (this.Items == null)
            {
                return;
            }

            DateTimeWrapper selectedDateTimeWrapper = null;
            int             newMax;
            DateTime        firstAvailableDate = GetFirstAvailable(dateTime, out newMax);

            // Make a copy without any minutes / seconds ...
            DateTimeWrapper newData =
                new DateTimeWrapper(new DateTime(firstAvailableDate.Year,
                                                 firstAvailableDate.Month,
                                                 firstAvailableDate.Day));

            // One item is deleted but was selected..
            // Don't forget to reactivate a selected item
            Boolean oneItemMustBeDeletedAndIsSelected = false;

            // If new month have less day than last month
            if (newMax < this.Items.Count)
            {
                int numberOfLastDaysToDelete = this.Items.Count - newMax;
                for (int cpt = 0; cpt < numberOfLastDaysToDelete; cpt++)
                {
                    PickerSelectorItem item =
                        this.ItemContainerGenerator.ContainerFromItem(this.Items[this.Items.Count - 1]) as PickerSelectorItem;

                    if (item == null)
                    {
                        continue;
                    }

                    if (item.IsSelected)
                    {
                        oneItemMustBeDeletedAndIsSelected = true;
                    }

                    this.Items.RemoveAt(this.Items.Count - 1);
                }
            }


            for (int i = 0; i < newMax; i++)
            {
                // -----------------------------------------------------------------------------
                // Add or Update Items
                // -----------------------------------------------------------------------------
                if (this.Items.Count <= i)
                {
                    this.Items.Add(newData);
                }
                else
                {
                    // Verify the item already exists
                    var itemDate = ((DateTimeWrapper)this.Items[i]).DateTime;

                    if (itemDate != newData.DateTime)
                    {
                        this.Items[i] = newData;
                    }
                }

                // -----------------------------------------------------------------------------
                // Get the good selected itm
                // -----------------------------------------------------------------------------
                if (newData.DateTime == dateTime)
                {
                    selectedDateTimeWrapper = newData;
                }

                // -----------------------------------------------------------------------------
                // Get the next data, relative to original wrapper, then relative to firstWrapper
                // -----------------------------------------------------------------------------
                DateTime?nextData = null;

                // Get nex date
                switch (this.DataSourceType)
                {
                case DataSourceType.Year:
                    nextData = this.YearDataSource.GetNext(dateTime, firstAvailableDate, i + 1);
                    break;

                case DataSourceType.Month:
                    nextData = this.MonthDataSource.GetNext(dateTime, firstAvailableDate, i + 1);
                    break;

                case DataSourceType.Day:
                    nextData = this.DayDataSource.GetNext(dateTime, firstAvailableDate, i + 1);
                    break;
                }
                if (nextData == null)
                {
                    break;
                }

                newData = nextData.Value.ToDateTimeWrapper();
            }

            // Set the correct Selected Item
            if (selectedDateTimeWrapper != null)
            {
                this.SelectedItem = selectedDateTimeWrapper;
            }
            else if (oneItemMustBeDeletedAndIsSelected) // When 31 was selected and we are on a Month < 31 days (February, April ...)
            {
                this.SelectedItem = (DateTimeWrapper)this.Items[this.Items.Count - 1];
            }
            else
            {
                this.SelectedItem = (DateTimeWrapper)this.Items[0];
            }
        }