Ejemplo n.º 1
0
        public void RemoveChild(IElement control)
        {
            var element = WpfFactory.GetNativeObject <FrameworkElement>(control, "element", true);

            if (element != null)
            {
                canvas.Children.Remove(element);

                var label = element as ILabel;
                if (label != null)
                {
                    var textBlock = element as TextBlock;
                    if (textBlock != null)
                    {
                        textBlock.Foreground = label.ForegroundColor.GetBrush();
                    }
                }

                var handler = PropertyChanged;
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs("Children"));
                }
            }
        }
Ejemplo n.º 2
0
        public void AddChild(IElement control)
        {
            var element = WpfFactory.GetNativeObject <FrameworkElement>(control, "element", false);

            if (element != null)
            {
                if (element.Parent is Panel)
                {
                    ((Panel)element.Parent).Children.Remove(element);
                }

                canvas.Children.Add(element);

                if (highlighter.Opacity > 0)
                {
                    var label = element as ILabel;
                    if (label != null)
                    {
                        var textBlock = element as TextBlock;
                        if (textBlock != null)
                        {
                            textBlock.Foreground = (label.HighlightColor.IsDefaultColor ? label.ForegroundColor : label.HighlightColor).GetBrush();
                        }
                    }
                }

                var handler = PropertyChanged;
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs("Children"));
                }
            }
        }
Ejemplo n.º 3
0
 private void SetHighlighterOpacity(double opacity)
 {
     highlighter.Opacity = opacity;
     if (opacity == 0)
     {
         foreach (var label in Children.OfType <ILabel>())
         {
             var textBlock = WpfFactory.GetNativeObject <TextBlock>(label, "child", true);
             if (textBlock != null)
             {
                 textBlock.Foreground = label.ForegroundColor.GetBrush();
             }
         }
     }
     else
     {
         foreach (var label in Children.OfType <ILabel>())
         {
             var textBlock = WpfFactory.GetNativeObject <TextBlock>(label, "child", true);
             if (textBlock != null)
             {
                 textBlock.Foreground = (label.HighlightColor.IsDefaultColor ? label.ForegroundColor : label.HighlightColor).GetBrush();
             }
         }
     }
 }
Ejemplo n.º 4
0
        public override async void SetBackground(string imagePath, ContentStretch stretch)
        {
            System.Windows.Media.ImageBrush brush = null;
            BitmapImage bitmap = null;

            if (!string.IsNullOrWhiteSpace(imagePath))
            {
                bitmap = await WpfFactory.LoadBitmapAsync(imagePath);

                brush = new System.Windows.Media.ImageBrush(bitmap);
            }

            if (brush == null || bitmap == null)
            {
                backCanvas.Background = null;

                backCanvas.Height = double.NaN;
                backCanvas.Width  = double.NaN;
            }
            else
            {
                brush.Stretch         = (System.Windows.Media.Stretch)stretch;
                backCanvas.Background = brush;

                backCanvas.Height = bitmap.Height;
                backCanvas.Width  = bitmap.Width;
            }
        }
Ejemplo n.º 5
0
        public IMXView[] PopToView(IMXView view)
        {
            view = (IMXView)WpfFactory.GetNativeObject <UIElement>(view, "view", false);
            Parameter.CheckObjectExists(ViewStack, "history", view, "view");

            List <IMXView> views = null;

            if (ViewStack.Last() != view)
            {
                views = new List <IMXView>();
                while (ViewStack.Count > 1 && ViewStack[ViewStack.Count - 1] != view)
                {
                    var last = ViewStack.Last();
                    var pair = last as IPairable;
                    if (pair == null)
                    {
                        views.Add(last);
                    }
                    else
                    {
                        views.Add((pair.Pair as IMXView) ?? (IMXView)pair);
                    }

                    ViewStack.RemoveAt(ViewStack.Count - 1);
                }

                Content = ViewStack.Last();
            }

            return(views == null ? null : views.ToArray());
        }
Ejemplo n.º 6
0
        public async static Task <ImageBrush> GetImageBrush(this string uri)
        {
            if (string.IsNullOrWhiteSpace(uri))
            {
                return(null);
            }

            return(new ImageBrush(await WpfFactory.LoadBitmapAsync(uri)));
        }
Ejemplo n.º 7
0
        private async void SetSource(string uri)
        {
            var imageData = uri == null ? null : Device.ImageCache.Get(uri);

            if (imageData != null && (creationOptions & ImageCreationOptions.IgnoreCache) != 0)
            {
                Device.ImageCache.Remove(uri);
                imageData = null;
            }

            BitmapImage source = null;

            if (imageData == null)
            {
                if (uri != null && (uri.StartsWith("http") || uri.StartsWith("ftp")))
                {
                    source = new BitmapImage(new Uri(uri), new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache));
                }
                else
                {
                    source = await WpfFactory.LoadBitmapAsync(uri);
                }

                if (source != null)
                {
                    source.DownloadCompleted -= OnDownloadCompleted;
                    source.DownloadCompleted += OnDownloadCompleted;

                    if ((creationOptions & ImageCreationOptions.IgnoreCache) == 0)
                    {
                        Device.ImageCache.Add(uri, new ImageData(source));
                    }
                }
            }
            else
            {
                var data = imageData as ImageData;
                source = data == null ? null : data.Source;
            }

            image.Source = source;

            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs("Dimensions"));
            }

            var parent = this.GetParent <IPairable>() as FrameworkElement;

            if (parent != null)
            {
                parent.InvalidateMeasure();
            }
        }
Ejemplo n.º 8
0
        public void RemoveChild(IElement control)
        {
            var element = WpfFactory.GetNativeObject <FrameworkElement>(control, "element", true);

            if (element != null)
            {
                canvas.Children.Remove(element);
                OnPropertyChanged("Children");
            }
        }
Ejemplo n.º 9
0
        public void InsertView(int index, IMXView view)
        {
            Parameter.CheckIndex(ViewStack, "history", index);
            view = (IMXView)WpfFactory.GetNativeObject <UIElement>(view, "view", false);

            ViewStack.Insert(index, view);
            if (index == ViewStack.Count - 1)
            {
                Content = view;
            }
        }
Ejemplo n.º 10
0
        public void ReplaceView(IMXView currentView, IMXView newView)
        {
            currentView = (IMXView)WpfFactory.GetNativeObject <UIElement>(currentView, "currentView", false);
            int index = Parameter.CheckObjectExists(ViewStack, "history", currentView, "currentView");

            ViewStack[index] = (IMXView)WpfFactory.GetNativeObject <UIElement>(newView, "newView", false);

            if (index == ViewStack.Count - 1)
            {
                Content = ViewStack.Last();
            }
        }
Ejemplo n.º 11
0
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is HeaderFooter)
                {
                    return(((HeaderFooter)value).Element);
                }
                if (value is SectionCell)
                {
                    SectionCell sc = (SectionCell)value;

                    ICell cell = null;
                    if (sc.SectionCellRequested != null)
                    {
                        cell = sc.SectionCellRequested(sc.CellIndex, null);
                    }
                    else if (sc.CellRequested != null)
                    {
                        cell = sc.CellRequested(sc.SectionIndex, sc.CellIndex, null);
                    }
                    sc.Cell = cell;

                    CustomItemContainer container = cell as CustomItemContainer;
                    if (container != null)
                    {
                        var custom = container.CustomItem as FrameworkElement;
                        System.Windows.Controls.Grid.SetColumn(custom, sc.SectionIndex % 2);
                        return(custom);
                    }

                    var element = WpfFactory.GetNativeObject <FrameworkElement>(cell, "cell", true);
                    if (element != null)
                    {
                        System.Windows.Controls.Grid.SetColumn(element, sc.SectionIndex % 2);
                        element.Unloaded += (o, e) =>
                        {
                            var gridCell = o as IGridCell;
                            var view     = parameter as ListView;
                            if (view != null && gridCell != null)
                            {
                                view.SetSubmitValue(gridCell);
                            }
                        };
                    }

                    return(element);
                }

                return(value);
            }
Ejemplo n.º 12
0
        public void AddChild(IElement control)
        {
            var element = WpfFactory.GetNativeObject <FrameworkElement>(control, "element", false);

            if (element != null)
            {
                if (element.Parent is Panel)
                {
                    ((Panel)element.Parent).Children.Remove(element);
                }

                canvas.Children.Add(element);
                OnPropertyChanged("Children");
            }
        }
Ejemplo n.º 13
0
        public void Add(IMenuButton menuButton)
        {
            var button = WpfFactory.GetNativeObject <System.Windows.Controls.Button>(menuButton, "menuButton", false);

            if (button != null)
            {
                button.Click -= ClosePopup;
                button.Click += ClosePopup;

                button.Background = itemsControl.Background;
                button.Foreground = itemsControl.Foreground;

                var buttonBase = button as ButtonBase;
                if (buttonBase != null)
                {
                    buttonBase.HighlightColor = HighlightColor;
                }

                itemsControl.Items.Add(button);
            }

            if (itemsControl.Items.Count != 1)
            {
                SetImage(imagePath);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(menuButton.ImagePath))
                {
                    SetImage(menuButton.ImagePath);
                }

                if (!HasImage)
                {
                    Content    = menuButton.Title;
                    FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
                    FontSize   = 12;
                }
            }

            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs("ButtonCount"));
            }
        }
Ejemplo n.º 14
0
        private async void SetImage(string uri)
        {
            var grid = Content as System.Windows.Controls.Grid;

            if (grid != null)
            {
                if (grid.Children.Count > 1)
                {
                    grid.Children.RemoveAt(1);
                }

                grid.Children.Insert(1, new System.Windows.Controls.Image()
                {
                    Source = await WpfFactory.LoadBitmapAsync(uri)
                });
            }
        }
Ejemplo n.º 15
0
        public LoginControl(LoginLayer layer)
        {
            InitializeComponent();
            Layer = layer;
            this.SkinLayer(Layer.LayerStyle);

            TxtUser.GotFocus += (o, e) => TxtUser.SelectAll();

            if (layer.UsernameLabel != null)
            {
                LblUser.Text = layer.UsernameLabel;
            }
            if (layer.PasswordLabel != null)
            {
                LblPassword.Text = layer.PasswordLabel;
            }
            if (layer.DefaultUsername != null)
            {
                TxtUser.Text = layer.DefaultUsername;
            }

            if (!Layer.LayerStyle.ErrorTextColor.IsDefaultColor)
            {
                LblError.Foreground = Layer.LayerStyle.ErrorTextColor.GetBrush();
            }

            if (Layer.BrandImage != null)
            {
                var brandImage = WpfFactory.LoadBitmap(Layer.BrandImage.Location);
                if (brandImage != null)
                {
                    BrandImage.Source = brandImage;
                }
            }

            KeyUp += (o, e) =>
            {
                if (e.Key == Key.Enter)
                {
                    btnLogin_Click(o, e);
                }
            };
        }
Ejemplo n.º 16
0
        public async void Load(string fileName)
        {
            //if the first child is an image, that means something else was loaded and it should be cleared
            if (inkCanvas.Children.Count > 0 && inkCanvas.Children[0] is System.Windows.Controls.Image)
            {
                inkCanvas.Children.RemoveAt(0);
            }

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                var image = new System.Windows.Controls.Image()
                {
                    Source  = await WpfFactory.LoadBitmapAsync(fileName),
                    Stretch = System.Windows.Media.Stretch.None,
                };

                inkCanvas.Children.Insert(0, image);
            }
        }
Ejemplo n.º 17
0
        private static async void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var inlineImage = (InlineImage)sender;
            var bitmapImage = await WpfFactory.LoadBitmapAsync(inlineImage.Source);

            if (bitmapImage == null)
            {
                inlineImage.Height  = new FigureLength(0);
                inlineImage.Width   = new FigureLength(0);
                inlineImage.Margin  = new Thickness(0);
                inlineImage.Padding = new Thickness(0);
                return;
            }
            var setImage = new Action <object, EventArgs>((ob, ev) =>
            {
                var image = new System.Windows.Controls.Image
                {
                    Source           = bitmapImage,
                    Stretch          = Stretch.Uniform,
                    StretchDirection = StretchDirection.Both,
                    Margin           = new Thickness(0),
                    MaxHeight        = inlineImage.Height.IsAuto ? bitmapImage.PixelHeight : inlineImage.Height.Value,
                    MaxWidth         = inlineImage.Width.IsAuto ? bitmapImage.PixelWidth : inlineImage.Width.Value,
                };

                inlineImage.Width = new FigureLength(image.MaxWidth, FigureUnitType.Pixel);
                inlineImage.Blocks.Clear();
                inlineImage.Blocks.Add(new BlockUIContainer {
                    Child = image, Padding = new Thickness(0), Margin = new Thickness(0),
                });
                inlineImage.ToolTip = inlineImage.ToolTip;
            });

            if (bitmapImage.IsDownloading)
            {
                bitmapImage.DownloadCompleted += (ob, ev) => setImage(ob, ev);
            }
            else
            {
                setImage(bitmapImage, EventArgs.Empty);
            }
        }
Ejemplo n.º 18
0
 public static async void SkinLayer(this FrameworkElement control, Style style)
 {
     control.SetBinding(Control.ForegroundProperty, new Binding("TextColor")
     {
         Source = style, Converter = ColorConverter
     });
     if (string.IsNullOrWhiteSpace(style.LayerBackgroundImage))
     {
         control.SetBinding(Control.BackgroundProperty, new Binding("LayerBackgroundColor")
         {
             Source = style, Converter = ColorConverter,
         });
     }
     else
     {
         control.SetValue(Control.BackgroundProperty, new ImageBrush
         {
             ImageSource = await WpfFactory.LoadBitmapAsync(style.LayerBackgroundImage),
             Stretch     = Stretch.UniformToFill,
         });
     }
 }
Ejemplo n.º 19
0
        private async void SetImage(string uri)
        {
            Content = new System.Windows.Controls.Image()
            {
                Source = await WpfFactory.LoadBitmapAsync(uri)
            };

            if (!HasImage)
            {
                if (title == null)
                {
                    Content    = "\uE600";
                    FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/iFactr.Wpf;component/"), "./Resources/#WPF-Symbol");
                    FontSize   = 20;
                }
                else
                {
                    Content    = title;
                    FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
                    FontSize   = 12;
                }
            }
        }
Ejemplo n.º 20
0
        public void ReloadSections()
        {
            if (!firstColumnItems.IsEnabled)
            {
                return;
            }

            if (ColumnMode == UI.ColumnMode.TwoColumns)
            {
                if (secondColumnItems == null)
                {
                    secondColumnItems = new ListBox()
                    {
                        HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
                        ItemContainerStyle         = (Style)Resources["ListBoxItemStyle"],
                        ItemTemplateSelector       = new CellTemplateSelector(this),
                        BorderThickness            = new Thickness(0),
                        Background = firstColumnItems.Background,
                        Padding    = new Thickness(8, 0, 10, 0)
                    };
                    System.Windows.Controls.Grid.SetColumn(secondColumnItems, 1);
                    ScrollViewer.SetHorizontalScrollBarVisibility(secondColumnItems, ScrollBarVisibility.Disabled);
                    ScrollViewer.SetCanContentScroll(secondColumnItems, false);
                    KeyboardNavigation.SetTabNavigation(secondColumnItems, KeyboardNavigationMode.Continue);

                    secondColumnItems.SelectionChanged += (o, e) =>
                    {
                        if (e.AddedItems.Count > 0)
                        {
                            firstColumnItems.UnselectAll();
                        }
                    };

                    firstColumnItems.SelectionChanged += (o, e) =>
                    {
                        if (e.AddedItems.Count > 0 && secondColumnItems != null)
                        {
                            secondColumnItems.UnselectAll();
                        }
                    };
                }

                if (!container.Children.Contains(secondColumnItems))
                {
                    container.ColumnDefinitions.Insert(1, new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                    container.Children.Add(secondColumnItems);

                    ScrollViewer.SetVerticalScrollBarVisibility(firstColumnItems, ScrollBarVisibility.Hidden);
                    ScrollViewer.SetCanContentScroll(firstColumnItems, false);

                    var scroller = firstColumnItems.FindChild <ScrollViewer>(null);
                    if (scroller != null)
                    {
                        scroller.ScrollChanged -= SyncScrollBars;
                        scroller.ScrollChanged += SyncScrollBars;
                    }

                    secondColumnItems.ApplyTemplate();
                    scroller = secondColumnItems.FindChild <ScrollViewer>(null);
                    if (scroller != null)
                    {
                        scroller.ScrollChanged -= SyncScrollBars;
                        scroller.ScrollChanged += SyncScrollBars;
                    }
                }

                List <object> firstItems = new List <object>();
                for (int i = 0; i < Sections.Count; i += 2)
                {
                    Section section = Sections[i];
                    firstItems.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true)
                    });

                    for (int j = 0; j < section.ItemCount; j++)
                    {
                        var sc = new SectionCell()
                        {
                            CellIndex = j, SectionIndex = i
                        };
                        if (section.CellRequested != null)
                        {
                            sc.SectionCellRequested = section.CellRequested;
                        }
                        else
                        {
                            sc.CellRequested = CellRequested;
                        }

                        firstItems.Add(sc);
                    }

                    firstItems.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true)
                    });
                }

                firstColumnItems.ItemsSource = firstItems;
                firstColumnItems.Padding     = new Thickness(10, 0, 8 + SystemParameters.ScrollWidth, 0);

                List <object> secondItems = new List <object>();
                for (int i = 1; i < Sections.Count; i += 2)
                {
                    Section section = Sections[i];
                    secondItems.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true)
                    });

                    for (int j = 0; j < section.ItemCount; j++)
                    {
                        var sc = new SectionCell()
                        {
                            CellIndex = j, SectionIndex = i
                        };
                        if (section.CellRequested != null)
                        {
                            sc.SectionCellRequested = section.CellRequested;
                        }
                        else
                        {
                            sc.CellRequested = CellRequested;
                        }

                        secondItems.Add(sc);
                    }

                    secondItems.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true)
                    });
                }

                secondColumnItems.ItemsSource = secondItems;
            }
            else
            {
                if (secondColumnItems != null && container.Children.Contains(secondColumnItems))
                {
                    container.Children.Remove(secondColumnItems);
                    container.ColumnDefinitions.RemoveAt(1);

                    ScrollViewer.SetVerticalScrollBarVisibility(firstColumnItems, ScrollBarVisibility.Auto);
                    ScrollViewer.SetCanContentScroll(firstColumnItems, true);

                    var scroller = firstColumnItems.FindChild <ScrollViewer>(null);
                    if (scroller != null)
                    {
                        scroller.ScrollChanged -= SyncScrollBars;
                    }

                    scroller = secondColumnItems.FindChild <ScrollViewer>(null);
                    if (scroller != null)
                    {
                        scroller.ScrollChanged -= SyncScrollBars;
                    }

                    secondColumnItems = null;
                }

                var items = new List <object>();
                for (int i = 0; i < Sections.Count; i++)
                {
                    Section section = Sections[i];
                    items.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true)
                    });

                    for (int j = 0; j < section.ItemCount; j++)
                    {
                        var sc = new SectionCell()
                        {
                            CellIndex = j, SectionIndex = i
                        };
                        if (section.CellRequested != null)
                        {
                            sc.SectionCellRequested = section.CellRequested;
                        }
                        else
                        {
                            sc.CellRequested = CellRequested;
                        }

                        items.Add(sc);
                    }

                    items.Add(new HeaderFooter()
                    {
                        Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true)
                    });
                }

                firstColumnItems.ItemsSource = items;
                firstColumnItems.Padding     = new Thickness(0);
            }
        }
Ejemplo n.º 21
0
 public virtual void PushView(IMXView view)
 {
     ViewStack.Add((IMXView)WpfFactory.GetNativeObject <UIElement>(view, "view", false));
     Content = ViewStack.Last();
 }
Ejemplo n.º 22
0
 private async void SetSource(string uri)
 {
     image.Source = await WpfFactory.LoadBitmapAsync(uri);
 }