Esempio n. 1
0
        private void element_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender is DependencyObject)
            {
                TextBox txt;

                if (sender is TextBox)
                {
                    txt = sender as TextBox;
                }
                else
                {
                    txt = VisualTreeHelpers.FindChild <TextBox>(sender as DependencyObject);
                }

                if (txt != null)
                {
                    txt.TextChanged -= txt_TextChanged;
                    txt.TextChanged += txt_TextChanged;

                    txt.SelectionStart  = 0;
                    txt.SelectionLength = txt.Text.Length;

                    if (txt.SelectionLength != 0)
                    {
                        selectAllOnTextChanged = true;
                    }
                }
            }

            SelectedElement = sender as UIElement;
        }
Esempio n. 2
0
        private void AnimateCarousel()
        {
            var             carousel   = VisualTreeHelpers.FindChild <StackPanel>(ImageCarousel, "Carousel");
            Storyboard      storyboard = (this.Resources["CarouselStoryboard"] as Storyboard);
            DoubleAnimation animation  = storyboard.Children.First() as DoubleAnimation;

            Storyboard.SetTarget(animation, carousel);
            animation.To = -550 * _currentElement;
            storyboard.Begin();
        }
Esempio n. 3
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            AssociatedObject.Loaded -= OnLoaded;
            ScrollViewer             = VisualTreeHelpers.FindChild <ScrollViewer>(AssociatedObject);

            if (ScrollViewer != null)
            {
                ScrollViewer.PreviewMouseWheel += OnPreviewMouseWheel;
            }
        }
Esempio n. 4
0
        private static void AddSortGlyph(GridViewColumnHeader columnHeader, ListSortDirection direction, ImageSource sortGlyph)
        {
            var textBlock = VisualTreeHelpers.FindChild <TextBlock>(columnHeader);

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(textBlock);

            adornerLayer.Add(
                new SortGlyphAdorner(
                    textBlock,
                    direction,
                    sortGlyph
                    ));
        }
Esempio n. 5
0
        /// <summary>
        /// Called when a data grid cell got focus.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private static void OnDataGridCellGotFocus(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource.GetType() == typeof(DataGridCell))
            {
                DataGrid dataGrid = (DataGrid)sender;
                dataGrid.BeginEdit(e);

                Control control = VisualTreeHelpers.FindChild <Control>(e.OriginalSource as DataGridCell);
                if (control != null)
                {
                    control.Focus();
                }
            }
        }
Esempio n. 6
0
 private void NavigateAction(string url)
 {
     if (url.StartsWith("#"))
     {
         var element = VisualTreeHelpers.FindChild <UIElement>(stack, string.Concat(url.Skip(1)));
         scrollViewer.ScrollToVerticalOffset(element.TranslatePoint(new Point(0, 0), stack).Y);
     }
     else
     {
         var nextPage = AllPages.Single(x => x.Path == url);
         onNavigating(nextPage);
         NavigationService?.Navigate(nextPage);
     }
 }
Esempio n. 7
0
        private static void RemoveSortGlyph(GridViewColumnHeader columnHeader)
        {
            var textBlock = VisualTreeHelpers.FindChild <TextBlock>(columnHeader);

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(textBlock);

            Adorner[] adorners = adornerLayer.GetAdorners(textBlock);

            if (adorners != null)
            {
                foreach (Adorner adorner in adorners)
                {
                    if (adorner is SortGlyphAdorner)
                    {
                        adornerLayer.Remove(adorner);
                    }
                }
            }
        }
        private async void FlipViewOfSectionsItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((FlipView)sender).SelectedItem == null)
            {
                return;
            }

            // http://stackoverflow.com/a/26611106/5303344
            //HACKYFIX: Daniel note:  Very hacky workaround for an api issue
            //Microsoft's api for getting item controls for the flipview item fail on the very first media selection change for some reason.  Basically we ignore the
            //first media selection changed event but spawn a thread to redo the ignored selection changed, hopefully allowing time for whatever is going on
            //with the api to get things sorted out so we can call the "ContainerFromItem" function and actually get the control we need
            if (_hackyfix == 0 || _hackyfix == 1)
            {
                _hackyfix++;

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    FlipViewOfSectionsItems_SelectionChanged(sender, e);
                });

                return;
            }

            if (((FlipView)sender).SelectedItem.GetType().Name == "Item")
            {
                loadedItem = (Item)((FlipView)sender).SelectedItem;
                FlipView     flipView = (FlipView)sender;
                FlipViewItem flipViewItemContainer = (FlipViewItem)flipView.ContainerFromItem(loadedItem);

                if (flipViewItemContainer == null)
                {
                    return;
                }

                if (loadedItem.item_type == "text")
                {
                    WebView webview = VisualTreeHelpers.FindChild <WebView>(flipViewItemContainer, "ItemWebView");
                    webview.NavigateToString(loadedItem.item_text);
                }
            }
        }
Esempio n. 9
0
        private void getTemperaturePoints(out Point[] temp, out Point[] feelsLike)
        {
            const double vMargin = 10;

            ScrollViewer scroll    = VisualTreeHelpers.FindChild <ScrollViewer>(listWeather);
            double       width     = scroll.ExtentWidth;
            int          count     = listWeather.Items.Count;
            double       itemWidth = width / count;

            double min = double.PositiveInfinity;
            double max = double.NegativeInfinity;

            foreach (WeatherForecastItem item in Component.Forecast)
            {
                min = Math.Min(item.MainInfo.Temperature, min);
                max = Math.Max(item.MainInfo.Temperature, max);

                min = Math.Min(item.MainInfo.FeelsLike, min);
                max = Math.Max(item.MainInfo.FeelsLike, max);
            }

            List <Point> points  = new List <Point>();
            List <Point> points2 = new List <Point>();

            for (int i = 0; i < Component.Forecast.Count; i++)
            {
                double top = 1 - (Component.Forecast[i].MainInfo.Temperature - min) / (max - min);
                points.Add(new Point(itemWidth / 2 + i * itemWidth, (canvasTemperature.ActualHeight - vMargin * 2) * top + vMargin));

                double top2 = 1 - (Component.Forecast[i].MainInfo.FeelsLike - min) / (max - min);
                points2.Add(new Point(itemWidth / 2 + i * itemWidth, (canvasTemperature.ActualHeight - vMargin * 2) * top2 + vMargin));
            }

            temp      = points.ToArray();
            feelsLike = points2.ToArray();
        }