Example #1
0
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     Thickness thick;
     thick.Top = 400;
     TextBlock txt = new TextBlock
     {
         Text = "Binding This Style in C#",
         VerticalAlignment = VerticalAlignment.Center,
         HorizontalAlignment = HorizontalAlignment.Center,
         Margin = thick,
         FontSize = 60,
         FontFamily = new FontFamily("Matura MT Script Capitals")
     };
     // Dynamically bind to an existed style.
     // 1. Setup the source.
     PropertyPath pPath = new PropertyPath("Foreground");
     Binding target = new Binding
     {
         ElementName = "topTxt",
         Path = pPath
     };
     // 2. Bind to the source. It is a DependencyObject, so you must use TextBlock.Foreground instead of Foreground.
     txt.SetBinding(TextBlock.ForegroundProperty, target);
     (this.Content as Grid).Children.Add(txt);
 }
        /// <summary>Generates the cell for the given item. </summary>
        /// <param name="dataGrid"></param>
        /// <param name="dataItem">The item to generate the cell for. </param>
        /// <returns>The <see cref="DataGridCellBase"/>. </returns>
        public override DataGridCellBase CreateCell(DataGrid dataGrid, object dataItem)
        {
            var block = new TextBlock();
            block.VerticalAlignment = VerticalAlignment.Center;

            if (FontSize <= 0)
                FontSize = dataGrid.FontSize;

            CreateBinding(StyleProperty, "Style", block, TextBlock.StyleProperty);
            CreateBinding(FontStyleProperty, "FontStyle", block, TextBlock.FontStyleProperty);
            CreateBinding(FontSizeProperty, "FontSize", block, TextBlock.FontSizeProperty);
            CreateBinding(ForegroundProperty, "Foreground", block, TextBlock.ForegroundProperty);

            if (Binding != null)
                block.SetBinding(TextBlock.TextProperty, Binding);

            return new DefaultDataGridCell(block);
        }
		public override DataGridCell GenerateElement(object dataItem)
		{
			var block = new TextBlock();
			block.VerticalAlignment = VerticalAlignment.Center;

			if (style != null)
				block.Style = style;

			if (fontSize.HasValue)
				block.FontSize = fontSize.Value;

			if (fontStyle.HasValue)
				block.FontStyle = fontStyle.Value;

			if (foreground != null)
				block.Foreground = foreground;

			if (Binding != null)
				block.SetBinding(TextBlock.TextProperty, Binding);

			return new DefaultDataGridCell(block);
		}
Example #4
0
        internal TextBlock BindATextBlock(int rotate)
        {
            var tb = new TextBlock();

            tb.SetBinding(TextBlock.FontFamilyProperty,
                new Binding {Path = new PropertyPath("FontFamily"), Source = this});
            tb.SetBinding(TextBlock.FontSizeProperty,
                new Binding {Path = new PropertyPath("FontSize"), Source = this});
            tb.SetBinding(TextBlock.FontStretchProperty,
                new Binding {Path = new PropertyPath("FontStretch"), Source = this});
            tb.SetBinding(TextBlock.FontStyleProperty,
                new Binding {Path = new PropertyPath("FontStyle"), Source = this});
            tb.SetBinding(TextBlock.FontWeightProperty,
                new Binding {Path = new PropertyPath("FontWeight"), Source = this});
            tb.SetBinding(TextBlock.ForegroundProperty,
                new Binding {Path = new PropertyPath("Foreground"), Source = this});
            tb.SetBinding(VisibilityProperty,
                new Binding {Path = new PropertyPath("Visibility"), Source = this});
            return tb;
        }
Example #5
0
        private void UpdateTemplate()
        {
            var stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            Content = stackPanel;

            var titleText = new TextBlock
            {
                Style = _pageSubHeaderTextStyle,
                TextWrapping = TextWrapping.Wrap,
            };
            stackPanel.Children.Add(titleText);
            var hasTitle = PopupInfo != null && PopupInfo.Title != null && PopupInfo.Title.Trim().Length > 0;
            if (hasTitle)
            {
                titleText.SetBinding(InlineCollectionProperty, new Binding
                {
                    Path = new PropertyPath("Attributes"),
                    Source = this,
                    Converter = new StringFormatToInlineCollectionConverter(),
                    ConverterParameter = PopupInfo.Title
                });
            }
            if (PopupInfo != null && PopupInfo.Description != null && PopupInfo.Description.Trim().Length > 0)
            {
                if (!hasTitle)
                {
                    hasTitle = true;
                    titleText.SetBinding(InlineCollectionProperty, new Binding
                    {
                        Path = new PropertyPath("Attributes"),
                        Source = this,
                        Converter = new StringFormatToInlineCollectionConverter(),
                        ConverterParameter = PopupInfo.Description
                    });
                }
                var desc = new RichTextBlock
                {
                    FontSize = _controlContentThemeFontSize,
                    FontFamily = _contentControlThemeFontFamily
                };
                stackPanel.Children.Add(desc);

                var p = new Paragraph();
                desc.Blocks.Add(p);

                BindingOperations.SetBinding(p,HtmlToTextConverter.HtmlToInlinesProperty, new Binding
                {
                    Path = new PropertyPath("Attributes"),
                    Source = this,
                    Converter = new HtmlToTextConverter(),
                    ConverterParameter = PopupInfo.Description
                });
            }
            else //Show attribute list
            {
                List<FieldInfo> displayFields = null;
                if (PopupInfo != null && PopupInfo.FieldInfos != null)
                {
                    displayFields = new List<FieldInfo>(PopupInfo.FieldInfos.Where(a => a.IsVisible));
                }
                if (displayFields == null)
                    return;
                var attributes = Attributes as IDictionary<string, object>;
                foreach (var item in displayFields)
                {
                    var sp = new StackPanel();
                    stackPanel.Children.Add(sp);
                    var l = new TextBlock
                    {
                        Style = _baselineTextStyle,
                        Margin = new Thickness(0, 10, 0, 0),
                        Text = item.Label ?? item.FieldName,
                        Foreground = new SolidColorBrush(Colors.DarkGray),
                        TextWrapping = TextWrapping.Wrap,
                        TextTrimming = TextTrimming.WordEllipsis
                    };
                    sp.Children.Add(l);
                    if (!hasTitle)
                    {
                        hasTitle = true;
                        titleText.SetBinding(InlineCollectionProperty, new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                    var useHyperlink = attributes != null && attributes.ContainsKey(item.FieldName) &&
                        attributes[item.FieldName] is string && ((string)attributes[item.FieldName]).StartsWith("http");
                    if (useHyperlink || string.Equals("url", item.FieldName, StringComparison.OrdinalIgnoreCase))
                    {
                        var hyperlink = new HyperlinkButton();
                        sp.Children.Add(hyperlink);
                        hyperlink.SetBinding(HyperlinkButton.NavigateUriProperty,
                        new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.SetBinding(ContentProperty,
                        new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                        hyperlink.Template = (ControlTemplate)XamlReader.Load(
                            "<ControlTemplate TargetType='HyperlinkButton' xmlns='http://schemas.microsoft.com/client/2007' >" +
                            "<TextBlock Text='{TemplateBinding Content}' Padding='0' Margin='0' RenderTransformOrigin='0.5,0.5' TextWrapping='Wrap' TextTrimming ='WordEllipsis'>" +
                            "<TextBlock.RenderTransform>" +
                            "<CompositeTransform TranslateY='5' />" +
                            "</TextBlock.RenderTransform>" +
                            "</TextBlock>" +
                            "</ControlTemplate>");
                        hyperlink.FontFamily = new FontFamily("Segoe UI Light");
                        hyperlink.FontWeight = FontWeights.Normal;
                        hyperlink.Margin = new Thickness(0);
                        hyperlink.Padding = new Thickness(0);
                    }
                    else
                    {
                        var t = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        sp.Children.Add(t);
                        t.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path = new PropertyPath(string.Format("Attributes[{0}]", item.FieldName)),
                            Source = this
                        });
                    }
                }
            }
            if (PopupInfo != null && PopupInfo.MediaInfos != null)
            {
                foreach (var item in PopupInfo.MediaInfos)
                {
                    if (!string.IsNullOrEmpty(item.Title))
                    {
                        var mediaTitle = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            FontWeight = FontWeights.Bold,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaTitle);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path = new PropertyPath("Attributes"),
                                Source = this,
                                Converter = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Title
                            });
                        }
                        mediaTitle.SetBinding(TextBlock.TextProperty, new Binding
                        {
                             Path = new PropertyPath("Attributes"),
                             Source = this,
                             Converter = new StringFormatToStringConverter(),
                             ConverterParameter = item.Title
                        });
                    }
                    if (!string.IsNullOrEmpty(item.Caption))
                    {
                        var mediaCaption = new TextBlock
                        {
                            Style = _baselineTextStyle,
                            Margin = new Thickness(0, 10, 0, 0),
                            FontStyle = FontStyle.Italic,
                            TextWrapping = TextWrapping.Wrap,
                            TextTrimming = TextTrimming.WordEllipsis
                        };
                        stackPanel.Children.Add(mediaCaption);
                        if (!hasTitle)
                        {
                            hasTitle = true;
                            titleText.SetBinding(InlineCollectionProperty, new Binding
                            {
                                Path = new PropertyPath("Attributes"),
                                Source = this,
                                Converter = new StringFormatToInlineCollectionConverter(),
                                ConverterParameter = item.Caption
                            });
                        }
                        mediaCaption.SetBinding(TextBlock.TextProperty, new Binding
                        {
                            Path = new PropertyPath("Attributes"),
                            Source = this,
                            Converter = new StringFormatToStringConverter(),
                            ConverterParameter = item.Caption
                        });
                    }

                    IEnumerable<KeyValuePair<string,string>> fieldMappings = null;
                    if (PopupInfo != null && PopupInfo.FieldInfos != null)
                    {
                        fieldMappings = from f in PopupInfo.FieldInfos
                                        select (new KeyValuePair<string, string>(f.FieldName, f.Label ?? f.FieldName));
                    }
                    BaseChart chart = null;
                    switch (item.Type)
                    {
                        case MediaType.Image:
                            var imageGrid = new Grid();
                            stackPanel.Children.Add(imageGrid);
                            if (!string.IsNullOrEmpty(item.Value.SourceUrl))
                            {
                                var image = new Image
                                {
                                    Margin = new Thickness(0,10,0,0),
                                    Width = 200d,
                                    Height = 200d,
                                    Stretch = Stretch.UniformToFill
                                };
                                imageGrid.Children.Add(image);
                                image.SetBinding(Image.SourceProperty, new Binding
                                {
                                    Path = new PropertyPath("Attributes"),
                                    Source = this,
                                    Converter = new StringFormatToBitmapSourceConverter(),
                                    ConverterParameter = item.Value.SourceUrl
                                });
                            }
                            if (!string.IsNullOrEmpty(item.Value.LinkUrl))
                            {
                                var hyperlinkButton = new HyperlinkButton
                                {
                                    Margin = new Thickness(0, 10, 0, 0),
                                    Width = 200d,
                                    Height = 200d
                                };
                                imageGrid.Children.Add(hyperlinkButton);
                                hyperlinkButton.SetBinding(HyperlinkButton.NavigateUriProperty, new Binding
                                {
                                    Path = new PropertyPath("Attributes"),
                                    Source = this,
                                    Converter = new StringFormatToUriConverter(),
                                    ConverterParameter = item.Value.LinkUrl
                                });
                            }
                            break;
                        case MediaType.BarChart:
                                chart = new BarChart();
                                break;
                        case MediaType.ColumnChart:
                                chart = new ColumnChart();
                                break;
                        case MediaType.LineChart:
                                chart = new LineChart();
                                break;
                        case MediaType.PieChart:
                                //string normalizeField = item.Value.NormalizeField;
                                chart = new PieChart();
                                break;
                    }
                    if (chart != null)
                    {
                        var fieldString = string.Join(",", item.Value.Fields);
                        var normalizeField = item.Value.NormalizeField;
                        if (!string.IsNullOrEmpty(normalizeField) && !normalizeField.Equals("null"))
                            fieldString += BaseChart.NormalizeSeparator + normalizeField;
                        chart.Margin = new Thickness(0, 10, 0, 0);
                        chart.Fields = fieldString;
                        chart.Height = 200;
                        chart.Width = 200;
                        chart.FontSize = 10d;
                        var keyValuePairs = fieldMappings as KeyValuePair<string, string>[] ?? fieldMappings.ToArray();
                        if (keyValuePairs.Any())
                        {
                            chart.KeyToLabelDictionary = new ResourceDictionary();
                            foreach (var pair in keyValuePairs)
                                chart.KeyToLabelDictionary[pair.Key] = pair.Value;
                        }
                        stackPanel.Children.Add(chart);
                        chart.SetBinding(DataContextProperty, new Binding
                        {
                            Path = new PropertyPath("Attributes"),
                            Source = this,
                        });
                    }
                }
            }
        }
        private void Parent_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            if (SelectedTool == InkingToolMode.Annotate)
            {
                Point position = e.GetPosition(null);
                // Find if we're intersecting with the toolbar, because we don't want annotation screens there.
                IEnumerable<UIElement> intersectedElements = VisualTreeHelper.FindElementsInHostCoordinates(position, _inkToolbar);
                // Check what elements of the sender we're on top of. If there's a button, we'll intersect with our toggle button collection
                // to confirm whether we'd like to simply 'hittest' that button.
                IEnumerable<UIElement> allIntersectedElements = VisualTreeHelper.FindElementsInHostCoordinates(position, (UIElement)sender);

                // Not intersected with the toolbar and no togglebuttons (of ours) in the way indicating there's another annotation, go ahead
                // and create the XAML.
                if (intersectedElements.Count() == 0 && (AnnotationTogglers.Intersect(allIntersectedElements.OfType<ButtonBase>())).Count() == 0)
                {
                    var panel = new Grid { Width = 300, Height = 200 };
                    StackPanel collapsingPanel = new StackPanel { Orientation = Orientation.Horizontal };
                    var toggleButtonText = new TextBlock { DataContext = this, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
                    var toggleButtonId = "tb" + Guid.NewGuid().ToString();
                    var toggleButtonContent = new Grid();
                    toggleButtonContent.Children.Add(toggleButtonText);
                    toggleButtonContent.Children.Add(new FontIcon { FontFamily = new FontFamily("Segoe MDL2 Assets"), Glyph = "\uE70B" });
                    var toggleButton = new ToggleButton { Content = new Viewbox { Child = toggleButtonContent }, Name = toggleButtonId, RenderTransform = new TranslateTransform { X = -10 }, Width = 32, Height = 32, Template = null, VerticalAlignment = VerticalAlignment.Top };
                    toggleButton.AddHandler(ToggleButton.PointerPressedEvent, new PointerEventHandler(ToggleButton_PointerPressed), true);
                    toggleButton.AddHandler(ToggleButton.PointerReleasedEvent, new PointerEventHandler(ToggleButton_PointerReleased), true);
                    toggleButton.AddHandler(ToggleButton.PointerMovedEvent, new PointerEventHandler(ToggleButton_PointerMoved), true);

                    toggleButton.PointerReleased += ToggleButton_PointerReleased;
                    AnnotationTogglers.Add(toggleButton);
                    toggleButtonText.SetBinding(TextBlock.TextProperty, new Binding { Path = new PropertyPath("AnnotationTogglers"), Converter = listIndexerConverter, ConverterParameter = toggleButtonId, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
                    collapsingPanel.Children.Add(toggleButton);

                    var innerGrid = new Grid();

                    CommandBar richTextEditBar = new CommandBar();
                    var boldButton = new AppBarButton { Label = "Bold", Icon = new SymbolIcon(Symbol.Bold) };
                    // TODO: remove when destroyed
                    boldButton.Click += BoldButton_Click;
                    richTextEditBar.PrimaryCommands.Add(boldButton);
                    var italicButton = new AppBarButton { Label = "Italic", Icon = new SymbolIcon(Symbol.Italic) };
                    // TODO: remove when destroyed
                    italicButton.Click += ItalicButton_Click;
                    richTextEditBar.PrimaryCommands.Add(italicButton);

                    innerGrid.Children.Add(new RichEditBox { Header = richTextEditBar, Width = 200 });
                    var deleteIcon = new FontIcon { Name = "deleteIcon", FontFamily = new FontFamily("Segoe MDL2 Assets"), Glyph = "\uE74D", Margin = new Thickness(0, 0, 5, 5), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom };
                    deleteIcon.Tapped += new Windows.UI.Xaml.Input.TappedEventHandler((o, a) => { DeleteAnnotation(panel); });
                    innerGrid.Children.Add(deleteIcon);
                    innerGrid.SetBinding(Grid.VisibilityProperty, new Binding { ElementName = toggleButton.Name, Path = new PropertyPath("IsChecked"), Converter = booleanToVisibilityConverter });
                    collapsingPanel.Children.Add(innerGrid);
                    panel.Children.Add(collapsingPanel);

                    Canvas.SetLeft(panel, position.X);
                    Canvas.SetTop(panel, position.Y);

                    _annotationCanvas.Children.Add(panel);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Gets the template parts and sets binding.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _notificationBlock = base.GetTemplateChild(NotificationBlock) as TextBlock;
            _messageBlock = base.GetTemplateChild(MessageBlock) as TextBlock;
            _backTitleBlock = base.GetTemplateChild(BackTitleBlock) as TextBlock;

            //Do binding in code to avoid exposing unnecessary value converters.
            if (_notificationBlock != null)
            {
                Binding bindVisible = new Binding();
                bindVisible.Source = this;
                bindVisible.Path = new PropertyPath("DisplayNotification");
                bindVisible.Converter = new VisibilityConverter();
                bindVisible.ConverterParameter = false;
                _notificationBlock.SetBinding(TextBlock.VisibilityProperty, bindVisible);
            }

            if (_messageBlock != null)
            {
                Binding bindCollapsed = new Binding();
                bindCollapsed.Source = this;
                bindCollapsed.Path = new PropertyPath("DisplayNotification");
                bindCollapsed.Converter = new VisibilityConverter();
                bindCollapsed.ConverterParameter = true;
                _messageBlock.SetBinding(TextBlock.VisibilityProperty, bindCollapsed);
            }

            if (_backTitleBlock != null)
            {
                Binding bindTitle = new Binding();
                bindTitle.Source = this;
                bindTitle.Path = new PropertyPath("Title");
                bindTitle.Converter = new MultipleToSingleLineStringConverter();
                _backTitleBlock.SetBinding(TextBlock.TextProperty, bindTitle);
            }

            UpdateVisualState();
        }
Example #8
0
        private UWPControls.StackPanel CreateResultStackPanel()
        {
            var resultStackPanel = new UWPControls.StackPanel();

            //Dùng cho hiển thị Token

            UWPControls.TextBox fbTokenTextBox = new UWPControls.TextBox();
            fbTokenTextBox.Width           = 300;
            fbTokenTextBox.Margin          = new UWPXaml.Thickness(10);
            fbTokenTextBox.BorderThickness = new UWPXaml.Thickness(0);
            fbTokenTextBox.Background      = new UWPXaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
            fbTokenTextBox.IsReadOnly      = true;
            fbTokenTextBox.TextWrapping    = UWPXaml.TextWrapping.Wrap;
            fbTokenTextBox.SetBinding(UWPControls.TextBox.TextProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("FBToken"),
                Mode   = UWPXaml.Data.BindingMode.OneWay
            });

            UWPControls.Button copyTokenButton = new UWPControls.Button();
            copyTokenButton.Width   = 150;
            copyTokenButton.Margin  = new UWPXaml.Thickness(0, 0, 5, 0);
            copyTokenButton.Content = "Sao chép Token";
            copyTokenButton.Click  += (o, args) => { Clipboard.SetText(_viewModel.FBToken ?? string.Empty); };

            UWPControls.Button saveTokenButton = new UWPControls.Button {
                Width = 120, Content = "Lưu Token"
            };
            saveTokenButton.SetBinding(UWPControls.Button.CommandProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("SaveTokenCommand")
            });

            UWPControls.StackPanel successCommandButtonsStackPanel = new UWPControls.StackPanel();
            successCommandButtonsStackPanel.Orientation         = UWPControls.Orientation.Horizontal;
            successCommandButtonsStackPanel.Margin              = new UWPXaml.Thickness(10);
            successCommandButtonsStackPanel.HorizontalAlignment = UWPXaml.HorizontalAlignment.Center;
            successCommandButtonsStackPanel.Children.Add(copyTokenButton);
            successCommandButtonsStackPanel.Children.Add(saveTokenButton);


            UWPControls.StackPanel successStackPanel = new UWPControls.StackPanel();

            successStackPanel.Children.Add(fbTokenTextBox);
            successStackPanel.Children.Add(successCommandButtonsStackPanel);

            successStackPanel.SetBinding(UWPXaml.UIElement.VisibilityProperty,
                                         new UWPXaml.Data.Binding()
            {
                Source    = _viewModel,
                Path      = new UWPXaml.PropertyPath("FBToken"),
                Converter = new NullTovisibilityConverter()
            });

            //Dùng cho hiển thị lỗi
            UWPControls.StackPanel errorStackPanel = new UWPControls.StackPanel();

            UWPControls.TextBlock errorMsgTextBlock = new UWPControls.TextBlock();
            errorMsgTextBlock.Width        = 300;
            errorMsgTextBlock.TextWrapping = UWPXaml.TextWrapping.WrapWholeWords;
            errorMsgTextBlock.Foreground   = new UWPXaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
            errorMsgTextBlock.SetBinding(UWPControls.TextBlock.TextProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("ErrorMsg")
            });

            errorStackPanel.Children.Add(errorMsgTextBlock);

            //Thêm cả 2 panel success và error vào panel chính
            resultStackPanel.Children.Add(errorStackPanel);
            resultStackPanel.Children.Add(successStackPanel);

            return(resultStackPanel);
        }
Example #9
0
        public Grid InfoTile(int rowNum, int colNum)
        {

            Grid tile = new Grid();
            tile.Background = new SolidColorBrush(Color.FromArgb(255, 50, 50, 50));
            tile.Name = "GPSStatusTile";
            tile.Children.Clear();
            Grid.SetRow(tile, rowNum);
            Grid.SetColumn(tile, colNum);

            tile.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(3, GridUnitType.Star) });
            tile.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(4, GridUnitType.Star) });
            tile.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) });

            //aktualizace
            Viewbox viewUpdate = new Viewbox();
            viewUpdate.HorizontalAlignment = HorizontalAlignment.Stretch;
            viewUpdate.VerticalAlignment = VerticalAlignment.Stretch;

            StackPanel lastUpdateGrid = new StackPanel();

            TextBlock lastLocationTitle = new TextBlock();
            lastLocationTitle.Text = _resourceLoader.GetString("TextUpdateTime");
            lastLocationTitle.FontSize = Data.getFontSize_SmallText();
            lastLocationTitle.TextWrapping = TextWrapping.WrapWholeWords;
            lastLocationTitle.Padding = new Thickness(5, 5, 5, 0);
            lastUpdateGrid.Children.Add(lastLocationTitle);
            TextBlock lastLocationUpdate = new TextBlock();
            lastLocationUpdate.FontSize = Data.getFontSize_SmallText();
            lastLocationUpdate.TextWrapping = TextWrapping.WrapWholeWords;
            lastLocationUpdate.Padding = new Thickness(5, 5, 5, 0);
            Binding locationBinding2 = new Binding();
            locationBinding2.Source = App.ViewModel;
            locationBinding2.Path = new PropertyPath("LastPositionTime");
            lastLocationUpdate.SetBinding(TextBlock.TextProperty, locationBinding2);
            lastUpdateGrid.Children.Add(lastLocationUpdate);

            viewUpdate.Child = lastUpdateGrid;

            //gps
            Viewbox view = new Viewbox();
            view.HorizontalAlignment = HorizontalAlignment.Stretch;
            view.VerticalAlignment = VerticalAlignment.Stretch;
            Grid.SetRow(view, 1);
            Grid.SetRowSpan(view, 1);

            Grid tileGrid = new Grid();
            tileGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
            tileGrid.VerticalAlignment = VerticalAlignment.Stretch;

            tileGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
            tileGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
            tileGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });

            tileGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
            tileGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
            tileGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });

            Binding locationBinding = new Binding()
            {
                Source = App.ViewModel,
                Path = new PropertyPath("GPSStatus"),

            };
            locationBinding.Source = App.ViewModel;
            locationBinding.Path = new PropertyPath("GPSStatus");
            /*
            TextBlock text = new TextBlock()
            {
                FontSize = 10,
                Height = 32,
                Width = 80,
                Margin = new Thickness(0, 16, 0, 0),
                TextWrapping = TextWrapping.WrapWholeWords,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                TextAlignment = TextAlignment.Center,
            };
            text.SetBinding(TextBlock.TextProperty, locationBinding);
            Grid.SetColumn(text, 1);
            Grid.SetRow(text, 1);
            tileGrid.Children.Add(text);*/
            Image image = new Image()
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Stretch = Stretch.UniformToFill,
            };
            image.SetBinding(Image.SourceProperty, locationBinding);
            
            Grid.SetColumn(image, 1);
            Grid.SetRow(image, 1);
            tileGrid.Children.Add(image);
            view.Child = tileGrid;
            tile.Children.Add(view);
            tile.Children.Add(viewUpdate);
            return tile;

        }
Example #10
0
        /// <summary>
        /// Hlavní dlaždice pro zobrazení jména stanice a smajlíka.
        /// </summary>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <returns></returns>
        public Grid mainStatusTile(int rowNum, int colNum)
        {
            Grid tile = new Grid();
            tile.Opacity = 1;
            try
            {
                Binding colorBinding = new Binding();
                colorBinding.Source = App.ViewModel;
                colorBinding.Path = new PropertyPath("CurrentStation.Quality");
                colorBinding.Converter = new ColorQualityConverter();
                tile.SetBinding(Grid.BackgroundProperty, colorBinding);
            }
            catch (Exception)
            {
            } Grid.SetRow(tile, rowNum);
            Grid.SetColumn(tile, colNum);
            Grid.SetRowSpan(tile, 2);
            Grid.SetColumnSpan(tile, 2);


            RowDefinition rowdef1 = new RowDefinition();
            rowdef1.Height = new GridLength(1, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef1);
            RowDefinition rowdef2 = new RowDefinition();
            rowdef2.Height = new GridLength(2, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef2);
            RowDefinition rowdef3 = new RowDefinition();
            rowdef3.Height = new GridLength(1, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef3);

            ColumnDefinition coldef1 = new ColumnDefinition();
            coldef1.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef1);
            ColumnDefinition coldef2 = new ColumnDefinition();
            coldef2.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef2);
            ColumnDefinition coldef3 = new ColumnDefinition();
            coldef3.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef3);
            ColumnDefinition coldef4 = new ColumnDefinition();
            coldef4.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef4);
            ColumnDefinition coldef5 = new ColumnDefinition();
            coldef5.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef5);

            /*
            TextBlock statusTitle = new TextBlock();
            //bude pravděpodobně třeba změnit pro plynulé přepínání jazyka
            statusTitle.Text = _resourceLoader.GetString("StatusTitle");
            statusTitle.FontSize = Data.getFontSize_LargeText();
            statusTitle.VerticalAlignment = VerticalAlignment.Center;
            statusTitle.HorizontalAlignment = HorizontalAlignment.Center;
            Grid.SetColumnSpan(statusTitle, 2);
            tile.Children.Add(statusTitle);
            */

            Image img = new Image();
            //bude třeba změnit por plynulou změnu obrázku
            Binding imageBinding = new Binding();
            imageBinding.Source = App.ViewModel;
            imageBinding.Path = new PropertyPath("CurrentStation.Quality");
            imageBinding.Converter = new ImageQualityConverter();
            img.SetBinding(Image.SourceProperty, imageBinding);
            Grid.SetRow(img, 1);
            Grid.SetColumn(img, 1);
            Grid.SetColumnSpan(img, 3);
            img.Stretch = Stretch.Uniform;
            tile.Children.Add(img);

            Viewbox view = new Viewbox();
            TextBlock stationName = new TextBlock();
            Binding b = new Binding();
            try
            {
                Binding nameBinding = new Binding();
                nameBinding.Source = App.ViewModel;
                nameBinding.Path = new PropertyPath("CurrentStation.Name");
                stationName.SetBinding(TextBlock.TextProperty, nameBinding);
            }
            catch (Exception)
            {
            } 
            
            stationName.FontSize = Data.getFontSize_LargeText();
            stationName.TextAlignment = TextAlignment.Center;
            stationName.VerticalAlignment = VerticalAlignment.Center;
            stationName.FontWeight = FontWeights.Bold;
            stationName.FontSize = 20;
            stationName.Height = 20;
            stationName.Margin = new Thickness(5, 0, 5, 0);

            Grid.SetColumnSpan(view, 5);
            Grid.SetRow(view, 2);
            view.Child = stationName;
            view.Height = 40;
            //view.Margin = new Thickness(5, 0, 5, 0);
            tile.Children.Add(view);


            tile.Name = "mainStatusTile";

            return tile;
        }
Example #11
0
        public Grid statusTile_SO2(int rowNum, int colNum)
        {
            //pro pripad nemoznosti nacist stav
            string status = "error";

            Grid tile = new Grid();
            Grid.SetRow(tile, rowNum);
            Grid.SetColumn(tile, colNum);
            try
            {
                Binding colorBinding = new Binding();
                colorBinding.Source = App.ViewModel;
                colorBinding.Path = new PropertyPath("CurrentStation.So2.State");
                colorBinding.Converter = new ColorQualityConverter();
                tile.SetBinding(Grid.BackgroundProperty, colorBinding);
            }
            catch (Exception)            {            }

            RowDefinition rowdef1 = new RowDefinition();
            rowdef1.Height = new GridLength(2, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef1);
            RowDefinition rowdef2 = new RowDefinition();
            rowdef2.Height = new GridLength(4, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef2);
            RowDefinition rowdef3 = new RowDefinition();
            rowdef3.Height = new GridLength(2, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef3);
            RowDefinition rowdef4 = new RowDefinition();
            rowdef4.Height = new GridLength(1, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef4);
            RowDefinition rowdef5 = new RowDefinition();
            rowdef5.Height = new GridLength(2, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef5); 
            RowDefinition rowdef6 = new RowDefinition();
            rowdef6.Height = new GridLength(1, GridUnitType.Star);
            tile.RowDefinitions.Add(rowdef6);

            ColumnDefinition coldef1 = new ColumnDefinition();
            coldef1.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef1);
            ColumnDefinition coldef2 = new ColumnDefinition();
            coldef2.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef2);
            ColumnDefinition coldef3 = new ColumnDefinition();
            coldef3.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef3);
            ColumnDefinition coldef4 = new ColumnDefinition();
            coldef4.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef4);
            ColumnDefinition coldef5 = new ColumnDefinition();
            coldef5.Width = new GridLength(1, GridUnitType.Star);
            tile.ColumnDefinitions.Add(coldef5);

            //nabindování
            TextBlock ratingString = new TextBlock();
            ratingString.Text = "SO2";
            Binding valueBinding = new Binding();
            valueBinding.Source = App.ViewModel;
            valueBinding.Path = new PropertyPath("CurrentStation.So2.Value");
            valueBinding.Converter = new NegativeValueConverter();
            ratingString.SetBinding(TextBlock.TextProperty, valueBinding);    

            ratingString.Foreground = new SolidColorBrush(Colors.White);
            ratingString.FontSize = Data.getFontSize_StatuValue();
            ratingString.TextAlignment = TextAlignment.Center;
            ratingString.HorizontalAlignment = HorizontalAlignment.Center;
            ratingString.VerticalAlignment = VerticalAlignment.Center;

            ratingString.FontSize = 150;
            Viewbox view = new Viewbox();
            view.Child = ratingString;
            view.HorizontalAlignment = HorizontalAlignment.Center;
            view.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetColumn(view, 0);
            Grid.SetColumnSpan(view, 5);
            Grid.SetRow(view, 1);

            tile.Children.Add(view);
            
            TextBlock stationString = new TextBlock();
            try
            {
                Binding statusBinding = new Binding();
                statusBinding.Source = App.ViewModel;
                statusBinding.Path = new PropertyPath("CurrentStation.So2.State");
                statusBinding.Converter = new ColorQualityConverter();
                stationString.SetBinding(TextBlock.TextProperty, statusBinding);
            }
            catch (Exception)
            {
            } stationString.Foreground = new SolidColorBrush(Colors.White);
            stationString.TextAlignment = TextAlignment.Center;
            stationString.HorizontalAlignment = HorizontalAlignment.Center;
            stationString.VerticalAlignment = VerticalAlignment.Center;
            stationString.FontWeight = FontWeights.Bold;

            stationString.FontSize = 50;
            Viewbox view3 = new Viewbox();
            view3.Child = stationString;
            view3.HorizontalAlignment = HorizontalAlignment.Center;
            view3.VerticalAlignment = VerticalAlignment.Center;
            view3.Margin = new Thickness(3);
            Grid.SetColumnSpan(view3, 5);
            Grid.SetRow(view3, 2);

            tile.Children.Add(view3);


            TextBlock nameString = new TextBlock();
            nameString.Text = "SO\x2082";
            nameString.Foreground = new SolidColorBrush(Colors.White);
            nameString.TextAlignment = TextAlignment.Center;
            nameString.HorizontalAlignment = HorizontalAlignment.Center;
            nameString.FontWeight = FontWeights.Bold;
            nameString.VerticalAlignment = VerticalAlignment.Center;


            nameString.FontSize = 20;
            Viewbox view2 = new Viewbox();
            view2.Child = nameString;
            view2.HorizontalAlignment = HorizontalAlignment.Left;
            view2.VerticalAlignment = VerticalAlignment.Center;
            view2.Margin = new Thickness(10, 0, 0, 0);
            Grid.SetRow(view2, 4);
            Grid.SetColumnSpan(view2, 3);

            tile.Children.Add(view2);

            

            tile.Name = "statusTile";

            return tile;
        }
Example #12
0
        void CreateCellContent(DataGrid grid, DataGridPanel panel, Border bdr, CellRange rng)
        {
            // get row and column
            var r = panel.Rows[rng.Row];
            var c = panel.Columns[rng.Column];
            //var gr = r as GroupRow;

            // honor user templates (if the row has a backing data item)
            if (r.DataItem != null && c.CellTemplate != null && panel.CellType == CellType.Cell)
            {
                bdr.Padding = GetTemplatePadding(bdr.Padding);
                bdr.Child = GetTemplatedCell(grid, c.CellTemplate);
                return;
            }

            // get binding, unbound value for the cell
            var b = r.DataItem != null ? c.Binding : null;
            var ubVal = r.DataItem != null ? null : panel[rng.Row, rng.Column];

            // get foreground brush taking selected state into account
            var fore = GetForegroundBrush(grid, r, rng, grid.Foreground);

            // handle non-text types
            var type = c.DataType;
            TextBlock tb = null;
            CheckBox chk = null;
            if (// not a group, or hierarchical
                panel.CellType == CellType.Cell &&
                (type == typeof(bool) || type == typeof(bool?))) // and bool
            {
                // Boolean cells: use CheckBox
                chk = new CheckBox();
                chk.IsThreeState = type == typeof(bool?);
                chk.HorizontalAlignment = HorizontalAlignment.Center;
                chk.VerticalAlignment = VerticalAlignment.Center;
                chk.MinWidth = 32;

                chk.HorizontalAlignment = HorizontalAlignment.Stretch;
                chk.VerticalAlignment = VerticalAlignment.Stretch;
                chk.Margin = new Thickness(0, -10, 0, -10);

                chk.IsHitTestVisible = false;
                chk.IsTabStop = false;
                if (fore != null)
                {
                    chk.Foreground = fore;
                }

                bdr.Child = chk;
                if (b != null)
                {
                    chk.SetBinding(CheckBox.IsCheckedProperty, b);
                }
                else
                {
                    var value = ubVal as bool?;
                    chk.IsChecked = value;
                }
            }
            else
            {
                // use TextBlock for everything else (even empty cells)
                tb = new TextBlock();
                tb.VerticalAlignment = VerticalAlignment.Center;
                if (fore != null)
                {
                    tb.Foreground = fore;
                }
                bdr.Child = tb;

                // bound values
                if (b != null)
                {
                    // apply binding
                    tb.SetBinding(TextBlock.TextProperty, b);
                }
                else if (ubVal != null) // unbound values
                {
                    // get column format from column and/or binding
                    tb.Text = r.GetDataFormatted(c);
                }
            }

        }
        private void BindForegroundToValidationBrush(TextBlock textBlock)
        {
            var validationBrushBinding = new Binding
            {
                Source = this,
                Path = new PropertyPath("ValidationBrush")
            };

            textBlock.SetBinding(TextBlock.ForegroundProperty, validationBrushBinding);
        }
Example #14
0
        private void _OnIsEditingChanged(bool isEditing, Item item)
        {
            UpdateGlyph();
            if (_leftSide != null) MainGrid.Children.Remove(_leftSide);

            if (isEditing)
            {
                TextBox box = new TextBox() {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center };
                box.SetValue(Grid.ColumnProperty, 0);
                box.FontSize = FontSize;
                box.SetBinding(TextBox.TextProperty, new Binding()
                {
                    Source = this,
                    Path = new PropertyPath(ItemMode ? "Item.Name" : "EditableText"),
                    Mode = BindingMode.TwoWay
                });
                
                _leftSide = box;
            }
            else
            {
                TextBlock block = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center };
                block.SetValue(Grid.ColumnProperty, 0);
                block.SetBinding(TextBlock.TextProperty, new Binding()
                {
                    Source = this,
                    Path = new PropertyPath(ItemMode ? "Item.Name" : "EditableText"),
                    Mode = BindingMode.OneWay
                });
                _leftSide = block;
            }

            MainGrid.Children.Add(_leftSide);
        }
Example #15
0
        private void SetSubMenu()
        {
            CircleMenuPanel.Children.Clear();

            foreach (var item in ItemsSource)
            {
                var menuItem = item as CircleMenuItem;
                if (menuItem != null)
                {
                    var btn = new Button();
                    btn.Opacity = 0;
                    var bindTag = new Binding
                    {
                        Path = new PropertyPath("Id"),
                        Source = menuItem,
                        Mode = BindingMode.OneWay
                    };
                    btn.SetBinding(TagProperty, bindTag);//用Tag存储Id

                    var textBlock = new TextBlock();
                    var bindTitle = new Binding
                    {
                        Path = new PropertyPath("Title"),
                        Source = menuItem,
                        Mode = BindingMode.OneWay
                    };
                    textBlock.SetBinding(TextBlock.TextProperty,bindTitle);

                    btn.Content = textBlock;
                    var binding = new Binding()
                    {
                        Path = new PropertyPath("SubMenuStyle"),
                        RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.TemplatedParent },
                        Source = this
                    };
                    btn.SetBinding(StyleProperty, binding);
                    btn.Click += (s, e) =>
                    {
                        VisualStateManager.GoToState(this, VisualStateCollapsed, false);
                        if (SubClickCommand != null)
                        {
                            var sbtn = s as Button;
                            if (sbtn != null)
                                SubClickCommand(Convert.ToInt32(sbtn.Tag));
                        }
                        SetSubMenu();
                        VisualStateManager.GoToState(this, VisualStateExpanded, false);
                    };

                    CircleMenuPanel.Children.Add(btn);
                }
            }
        }