本文整理汇总了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);
}
}