本文整理汇总了C#中System.Windows.Documents.Run.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Run.SetBinding方法的具体用法?C# Run.SetBinding怎么用?C# Run.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.Run
的用法示例。
在下文中一共展示了Run.SetBinding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToBlock
/// <summary>
/// Convert "data" to a flow document block object. If data is already a block, the return value is data recast.
/// </summary>
/// <param name="dataContext">only used when bindable content needs to be created</param>
/// <param name="data"></param>
/// <returns></returns>
public static Block ConvertToBlock(object dataContext, object data)
{
if (data is Block)
return (Block)data;
else if (data is Inline)
return new Paragraph((Inline)data);
else if (data is BindingBase)
{
var run = new Run();
if (dataContext is BindingBase)
run.SetBinding(Run.DataContextProperty, (BindingBase)dataContext);
else
run.DataContext = dataContext;
run.SetBinding(Run.TextProperty, (BindingBase)data);
return new Paragraph(run);
}
else
{
var run = new Run();
run.Text = (data == null) ? string.Empty : data.ToString();
return new Paragraph(run);
}
}
示例2: ConvertToBlock
internal static Block ConvertToBlock(object dataContext, object data)
{
if (data is Block)
{
return (Block)data;
}
else if (data is Inline)
{
return new Paragraph((Inline)data);
}
else if (data is BindingBase)
{
Run run = new Run();
if (dataContext is BindingBase)
{
run.SetBinding(Run.DataContextProperty, (BindingBase)dataContext);
}
else
{
run.DataContext = dataContext;
}
run.SetBinding(Run.TextProperty, (BindingBase)data);
return new Paragraph(run);
}
else
{
Run run = new Run();
run.Text = (data == null) ? String.Empty : data.ToString();
return new Paragraph(run);
}
}
示例3: SetPlaceholder
protected void SetPlaceholder() {
Inlines.Clear();
var placeholder = Placeholder;
if (!string.IsNullOrEmpty(placeholder)) {
var inline = new Run { Text = placeholder };
inline.SetBinding(TextElement.ForegroundProperty, new Binding {
Path = new PropertyPath(nameof(Foreground)),
Source = this,
Converter = this
});
Inlines.Add(inline);
}
}
示例4: CreateTextBlock
public Run CreateTextBlock(string text, FontWeight weight, DependencyProperty foreground)
{
Run x = new Run (text);
x.FontWeight = weight;
if (foreground != null)
x.SetBinding (Run.ForegroundProperty, CreateBinding (this, foreground.Name, BindingMode.OneWay));
return x;
}
示例5: BuildElementInternal
protected override Inline BuildElementInternal()
{
Run buildElementInternal;
if (textBinding != null)
{
buildElementInternal = new Run();
buildElementInternal.SetBinding(Run.TextProperty, textBinding);
}
else
buildElementInternal = new Run(Text);
if (style != null)
buildElementInternal.SetResourceReference(FrameworkContentElement.StyleProperty, style);
return buildElementInternal;
}
示例6: ConvertToBlock
/// <summary>
/// Convert "data" to a flow document block object. If data is already a block, the return value is data recast.
/// </summary>
/// <param name="dataContext">only used when bindable content needs to be created</param>
/// <param name="data"></param>
/// <returns></returns>
public static Block ConvertToBlock(object dataContext, object data)
{
var block = data as Block;
if (block != null) return block;
var inline = data as Inline;
if (inline != null) return new Paragraph(inline);
var bindingBase = data as BindingBase;
if (bindingBase != null)
{
var run = new Run();
var dataContextBindingBase = dataContext as BindingBase;
if (dataContextBindingBase != null)
run.SetBinding(DataContextProperty, dataContextBindingBase);
else
run.DataContext = dataContext;
run.SetBinding(Run.TextProperty, bindingBase);
return new Paragraph(run);
}
return new Paragraph(new Run { Text = (data == null) ? string.Empty : data.ToString() });
}
示例7: TextChanged
private static void TextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Label lbl = d as Label;
TextBlock block = d as TextBlock;
if (lbl != null)
{
block = lbl.Content as TextBlock;
if (block == null)
{
string lblChild = lbl.Content as string;
TextBlock newChild = new TextBlock { Text = lblChild ?? "" };
lbl.Content = newChild;
block = newChild;
}
}
if (block == null)
{
return;
}
string searchText = GetHighlightText(d);
string blockText = GetSourceText(d);
if (blockText == null)
{
return;
}
int last = 0;
block.Inlines.Clear();
if (!string.IsNullOrEmpty(searchText))
{
IReadOnlyList<PackageSearchUtil.Range> matches = PackageSearchUtil.ForTerm(searchText).GetMatchesInText(blockText);
for (int i = 0; i < matches.Count; ++i)
{
if (matches[i].Length == 0)
{
continue;
}
if (last < matches[i].Start)
{
string inserted = blockText.Substring(last, matches[i].Start - last);
block.Inlines.Add(inserted);
last += inserted.Length;
}
Run highlight = new Run(matches[i].ToString());
highlight.SetBinding(FrameworkContentElement.StyleProperty, new Binding
{
Mode = BindingMode.OneWay,
Source = d,
Path = new PropertyPath(HighlightStyleProperty)
});
block.Inlines.Add(highlight);
last += matches[i].Length;
}
}
if (last < blockText.Length)
{
block.Inlines.Add(blockText.Substring(last));
}
}