本文整理汇总了C#中System.Windows.Documents.Hyperlink.SetResourceReference方法的典型用法代码示例。如果您正苦于以下问题:C# Hyperlink.SetResourceReference方法的具体用法?C# Hyperlink.SetResourceReference怎么用?C# Hyperlink.SetResourceReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.Hyperlink
的用法示例。
在下文中一共展示了Hyperlink.SetResourceReference方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecorateAsHyperlink
public static Inline DecorateAsHyperlink(string text)
{
var hyperlink = new Hyperlink(new Run(text)) { NavigateUri = new Uri(text) };
hyperlink.Click += HyperlinkClickHandler;
hyperlink.SetResourceReference(FrameworkContentElement.StyleProperty, "hyperlinkStyle");
return hyperlink;
}
示例2: Render
/// <summary>
/// Renders the specified chat node to the client.
/// </summary>
/// <param name="node">The node to append.</param>
/// <remarks>
/// <para>The return value of this function is a reference to the outermost <see cref="Inline">Inline</see> constructed
/// by this function. It may create additional inner elements as needed.</para>
/// </remarks>
/// <returns>
/// Returns an object instance of <see cref="Inline">Inline</see> that can be appended to the HTML document.
/// </returns>
public virtual Inline Render(ChatNode node)
{
Inline result;
if (node == ChatNode.NewLine)
{
result = new LineBreak();
}
else if (node.LinkUri == null)
{
Run run = new Run();
if (node.CssClass != null)
{
run.Style = ResourceProvider[node.CssClass] as Style;
run.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
}
else if (node.Color != GdiColor.Empty)
{
run.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
}
run.Text = node.Text;
result = run;
}
else // need to make a link.
{
Hyperlink link = new Hyperlink();
link.Inlines.Add(new Run(node.Text));
link.NavigateUri = node.LinkUri;
if (node.CssClass != null)
{
link.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
}
else if (node.Color != GdiColor.Empty)
{
link.Foreground = new SolidColorBrush(WpfColor.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
}
link.ToolTip = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri.ToString());
result = link;
}
return result;
}
示例3: PrepareTweetDocument
private static void PrepareTweetDocument(TextBlock textBlock, MetroTwitStatusBase tweet, bool Notification = false)
{
if (DesignerProperties.GetIsInDesignMode((DependencyObject) textBlock))
return;
try
{
if (textBlock != null && textBlock.Inlines != null && textBlock.Inlines.Count > 0)
textBlock.Inlines.Clear();
}
catch
{
foreach (Inline inline in Enumerable.ToArray<Inline>((IEnumerable<Inline>) textBlock.Inlines))
textBlock.Inlines.Remove(inline);
}
if (Notification)
{
Span span1 = new Span();
span1.FontWeight = FontWeights.SemiBold;
Span span2 = span1;
Hyperlink hyperlink = new Hyperlink((Inline) new Run("@" + tweet.User.ScreenName));
hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object)"ModernTextLighterBrush");
hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand")
{
Mode = BindingMode.OneWay
});
hyperlink.SetBinding(Hyperlink.CommandParameterProperty, (BindingBase) new Binding("CurrentTweet.User.ScreenName")
{
Mode = BindingMode.OneWay
});
((TextElementCollection<Inline>) span2.Inlines).Add((Inline) hyperlink);
((TextElementCollection<Inline>) span2.Inlines).Add((Inline) new Run()
{
Text = ": "
});
((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) span2);
}
if (tweet != null && tweet.Entities != null && tweet.Entities.Count > 0)
{
try
{
int[] numArray = StringInfo.ParseCombiningCharacters(tweet.RawText);
IOrderedEnumerable<Entity> orderedEnumerable = Enumerable.OrderBy<Entity, int>((IEnumerable<Entity>) tweet.Entities, (Func<Entity, int>) (x => x.StartIndex));
int num1 = 0;
foreach (Entity entity in (IEnumerable<Entity>) orderedEnumerable)
{
int num2 = 0;
if (numArray.Length < tweet.RawText.Length && entity.StartIndex < numArray.Length)
num2 = numArray[entity.StartIndex] - entity.StartIndex;
int num3 = entity.StartIndex + num2;
int num4 = entity.EndIndex + num2;
int startIndex1 = num1;
if (num3 > startIndex1 && startIndex1 < numArray.Length && startIndex1 + (num3 - startIndex1) < numArray.Length)
{
string input = WebUtility.HtmlDecode(tweet.RawText.Substring(startIndex1, num3 - startIndex1));
if (!string.IsNullOrEmpty(input))
{
Run run = new Run(Regex.Replace(input, "\n{2,}|(\r\n){2,}", "\n\n"));
((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) run);
}
}
if (entity is MentionEntity)
{
MentionEntity mentionEntity = entity as MentionEntity;
if (!string.IsNullOrEmpty(mentionEntity.ScreenName))
{
Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("@" + mentionEntity.ScreenName))
{
CommandParameter = (object) ("@" + mentionEntity.ScreenName)
};
hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkUsername");
hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand")
{
Mode = BindingMode.OneTime
});
((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) hyperlink);
hyperlink.ContextMenu = new ContextMenu();
MenuItem menuItem1 = new MenuItem();
menuItem1.Header = (object) "Filter tweets from this user";
menuItem1.CommandParameter = hyperlink.CommandParameter;
MenuItem menuItem2 = menuItem1;
menuItem2.SetBinding(MenuItem.CommandProperty, (BindingBase) new Binding("FilterCommand")
{
Mode = BindingMode.OneTime
});
hyperlink.ContextMenu.Items.Add((object) menuItem2);
}
}
else if (entity is HashTagEntity)
{
HashTagEntity hashTagEntity = entity as HashTagEntity;
if (!string.IsNullOrEmpty(hashTagEntity.Text))
{
Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("#" + hashTagEntity.Text))
{
CommandParameter = (object) ("#" + hashTagEntity.Text)
};
hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkHashtag");
hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("TagsCommand")
{
Mode = BindingMode.OneTime
//.........这里部分代码省略.........
示例4: InsertHyperLink
//private static bool InsertName(ICollection<Inline> textblock, string name)
//{
// if (string.IsNullOrEmpty(name))
// return false;
// textblock.Add(new Hyperlink(new Run(name)));
// textblock.Add(new Run(":"));
// return true;
//}
private static void InsertHyperLink(ICollection<Inline> textblock, Token token)
{
var ut = token.text;
if (string.IsNullOrEmpty(ut))
return;
if (ut.Length != token.text.Length)
textblock.Add(new Run(" "));
var run = ut.Replace(Properties.Resources.ShortUrlPrefix, string.Empty);
//create hyperlink
var h = new Hyperlink(new Run(run){FontWeight = FontWeights.SemiBold})
{
// NavigateUri = new Uri(ut,UriKind.Absolute),使用这个会直接调用到navigationservice中
Command = WeiZhiCommands.Navigate,
CommandParameter = ut,
ToolTip = ut,
};
h.ToolTipOpening +=
(s, e) =>
{
var dp =(Hyperlink) s;
if (dp.Tag != null)
return;
var mem = MemoryCache.Default;
var ui = (UrlInfo) mem.Get(ut);
if (ui == null)
return;
dp.Tag = ui;
if (!string.IsNullOrEmpty(ui.topic()))
dp.ToolTip = ui.topic() + " / " + EnumDescription.Get(ui.type);
else dp.ToolTip = ui.url_long + " / " + EnumDescription.Get(ui.type);
};
h.SetResourceReference(TextElement.ForegroundProperty, "MetroColorFeatureBrush");
textblock.Add(h);
var memc = MemoryCache.Default;
var uinfo = (UrlInfo)memc.Get(ut);
if (uinfo != null)
{
if (uinfo.type == UrlType.Video)
textblock.Add(new Run("\uE173"));
else if (uinfo.type == UrlType.Music)
textblock.Add(new Run("\u266C"));
}
else if (ut.Length != token.text.Length)
textblock.Add(new Run(" "));
}
示例5: CreateInfoText
private UIElement CreateInfoText(String xmlns, String url)
{
var textBlock = new TextBlock();
Hyperlink hl = new Hyperlink(new Run(url));
textBlock.Inlines.AddRange(new Inline[] {
new Bold(new Run("Prefix: ")),
new Run(xmlns),
new LineBreak(),
new Bold(new Run("Namespace: ")),
hl
});
// set styles in order to support other
// visual studio themes on 2012/2013
var brushKey = VsColors.ToolTipBrushKey;
if ( brushKey != null ) {
textBlock.SetResourceReference(TextBlock.BackgroundProperty, brushKey);
}
textBlock.SetResourceReference(TextBlock.ForegroundProperty, VsColors.ToolTipTextBrushKey);
hl.SetResourceReference(Hyperlink.ForegroundProperty, VsColors.PanelHyperlinkBrushKey);
return textBlock;
}