Ejemplo n.º 1
0
        protected override void OnManipulationCompleted(ManipulationCompletedRoutedEventArgs e)
        {
            LoopItemsPanel itemsPanel = e.Container as LoopItemsPanel;

            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;
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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 <LoopItemsPanel>();

            // 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;
        }
Ejemplo n.º 4
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];
            }
        }
Ejemplo n.º 5
0
        private static void IsSelectedChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            PickerSelectorItem pickerSelectorItem = (PickerSelectorItem)dependencyObject;

            pickerSelectorItem.ManageVisualStates();
        }