當前位置: 首頁>>代碼示例>>C#>>正文


C# TextBlock.Bind方法代碼示例

本文整理匯總了C#中System.Windows.Controls.TextBlock.Bind方法的典型用法代碼示例。如果您正苦於以下問題:C# TextBlock.Bind方法的具體用法?C# TextBlock.Bind怎麽用?C# TextBlock.Bind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Controls.TextBlock的用法示例。


在下文中一共展示了TextBlock.Bind方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdateView

        protected void UpdateView()
        {
            var scrollViewer = this.GetTemplateChild("PART_ContentHost") as ScrollViewer;
            var whenFocused = scrollViewer?.NestedChildren().OfType<ScrollContentPresenter>().SingleOrDefault();
            var grid = whenFocused?.Parent as Grid;
            if (scrollViewer == null || whenFocused == null || grid == null)
            {
                if (!this.IsLoaded)
                {
                    this.Loaded += OnLoaded;
                    return;
                }

                if (this.IsArrangeValid == false)
                {
                    // retry after arrange
                    // using the Loaded event does not work if template is changed in runtime.
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(this.UpdateView));
                    return;
                }

                if (DesignerProperties.GetIsInDesignMode(this))
                {
                    var message = $"The template does not match the expected template. Cannot use formatting\r\n" +
                                  $"The expected template is (pseudo)\r\n" +
                                  $"{nameof(ScrollViewer)}: {(scrollViewer == null ? "null" : string.Empty)}\r\n" +
                                  $"  {nameof(Grid)}: {(grid == null ? "null" : string.Empty)}\r\n" +
                                  $"    {nameof(ScrollContentPresenter)}: {(whenFocused == null ? "null" : string.Empty)}";
                    throw new InvalidOperationException(message);
                }
                else
                {
                    // Falling back to vanilla textbox in runtime
                    return;
                }
            }

            var formattedBox = (TextBlock)grid.FindName(FormattedName);
            if (formattedBox == null)
            {
                var whenNotFocused = new TextBlock
                {
                    Name = FormattedName,
                    VerticalAlignment = VerticalAlignment.Center
                };

                whenNotFocused.Bind(TextBlock.TextProperty)
                    .OneWayTo(this, FormattedTextProperty);

                whenNotFocused.Bind(MarginProperty)
                    .OneWayTo(whenFocused, MarginProperty, FormattedTextBlockMarginConverter.Default, whenFocused);

                whenNotFocused.Bind(VisibilityProperty)
                    .OneWayTo(this, IsKeyboardFocusWithinProperty, HiddenWhenTrueConverter.Default);

                grid.Children.Add(whenNotFocused);

                whenFocused.Bind(VisibilityProperty)
                    .OneWayTo(this, IsKeyboardFocusWithinProperty, VisibleWhenTrueConverter.Default);
            }
        }
開發者ID:gitter-badger,項目名稱:Gu.Wpf.NumericInput,代碼行數:61,代碼來源:BaseBox.cs


注:本文中的System.Windows.Controls.TextBlock.Bind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。