当前位置: 首页>>代码示例>>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;未经允许,请勿转载。