当前位置: 首页>>代码示例>>C#>>正文


C# TextBlock.SetBinding方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Controls.TextBlock.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# TextBlock.SetBinding方法的具体用法?C# TextBlock.SetBinding怎么用?C# TextBlock.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Controls.TextBlock的用法示例。


在下文中一共展示了TextBlock.SetBinding方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnNavigatedTo

 /// <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);
 }
开发者ID:ZWin8,项目名称:MetroGit,代码行数:30,代码来源:DataBindingDemo.xaml.cs

示例2: CreateCell

        /// <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);
        }
开发者ID:RareNCool,项目名称:MyToolkit,代码行数:22,代码来源:DataGridTextColumn.cs

示例3: GenerateElement

		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);
		}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:22,代码来源:DataGridTextColumn.cs

示例4: BindATextBlock

        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;
        }
开发者ID:beto-rodriguez,项目名称:Live-Charts,代码行数:20,代码来源:Series.cs

示例5: UpdateTemplate

        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
//.........这里部分代码省略.........
开发者ID:Esri,项目名称:arcgis-portalviewer-dotnet,代码行数:101,代码来源:Popup.cs

示例6: Parent_Tapped

        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);
                }
            }
        }
开发者ID:martijnhoogendoorn,项目名称:inkingbehavior,代码行数:59,代码来源:InkingBehavior.cs

示例7: OnApplyTemplate

        /// <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();
        }
开发者ID:king89,项目名称:MangaViewer,代码行数:43,代码来源:HubTile.cs

示例8: InfoTile

        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;

        }
开发者ID:Qerts,项目名称:Projekt-Pollution-MKII,代码行数:99,代码来源:Tile.cs

示例9: mainStatusTile

        /// <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);
//.........这里部分代码省略.........
开发者ID:Qerts,项目名称:Projekt-Pollution-MKII,代码行数:101,代码来源:Tile.cs

示例10: statusTile_SO2

        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;
//.........这里部分代码省略.........
开发者ID:Qerts,项目名称:Projekt-Pollution-MKII,代码行数:101,代码来源:Tile.cs

示例11: CreateCellContent

        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);
                }
            }

        }
开发者ID:GJian,项目名称:UWP-master,代码行数:84,代码来源:CellFactory.cs

示例12: BindForegroundToValidationBrush

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

            textBlock.SetBinding(TextBlock.ForegroundProperty, validationBrushBinding);
        }
开发者ID:MannusEtten,项目名称:uwp-validation,代码行数:10,代码来源:ValidationStackPanel.cs

示例13: SetSubMenu

        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);
                }
            }
        }
开发者ID:woniuchn,项目名称:blog_sample_codes,代码行数:53,代码来源:CircleMenu.cs


注:本文中的Windows.UI.Xaml.Controls.TextBlock.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。