Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF页面导航_Wpf_Controls_Styles_Wpftoolkit - Fatal编程技术网

WPF页面导航

WPF页面导航,wpf,controls,styles,wpftoolkit,Wpf,Controls,Styles,Wpftoolkit,我在WPF应用程序中使用自定义文本块,当我在WPF窗口中使用它时,效果很好,但当我在WPF页面中使用它时,会产生问题。当我单击自定义控件中的链接时,它会浏览该链接并在浏览器中显示,但WPF页面也会导航回另一个WPF页面(第一页) namespace Dtwitter.Controls { 公共类TweetTextBlock:TextBlock { 公共TweetTextBlock() { } #区域依赖属性 公共字符串TweetText { get{return(string)GetValue(

我在WPF应用程序中使用自定义文本块,当我在WPF窗口中使用它时,效果很好,但当我在WPF页面中使用它时,会产生问题。当我单击自定义控件中的链接时,它会浏览该链接并在浏览器中显示,但WPF页面也会导航回另一个WPF页面(第一页)

namespace Dtwitter.Controls
{
公共类TweetTextBlock:TextBlock
{
公共TweetTextBlock()
{
}
#区域依赖属性
公共字符串TweetText
{
get{return(string)GetValue(TweetTextProperty);}
设置{SetValue(TweetTextProperty,value);}
}
//使用DependencyProperty作为TweetText的后台存储。这将启用动画、样式、绑定等。。。
公共静态只读DependencyProperty TweetTextProperty=
DependencyProperty.Register(“TweetText”、typeof(string)、typeof(TweetTextBlock),
新的FrameworkPropertyMetadata(string.Empty,新的PropertyChangedCallback(OnTweetTextChanged));
#端区
私有静态无效OnTweetTextChanged(DependencyObject对象、DependencyPropertyChangedEventArgs参数)
{
string text=args.NewValue作为字符串;
如果(!string.IsNullOrEmpty(text))
{
TweetTextBlock textblock=(TweetTextBlock)obj;
textblock.Inlines.Clear();
textblock.Inlines.Add(“”);
string[]words=Regex.Split(text,@“([\(\)\{\}\[\]]);
字符串possibleUserName=words[0]。ToString();
如果((possibleUserName.Length>1)&&(possibleUserName.Substring(1,1)==“@”))
{
textblock=FormatName(textblock,possibleUserName);
words.SetValue(“,0);
}
foreach(单词中的字符串)
{
//可点击超链接
if(UrlShorteningService.IsUrl(word))
{
尝试
{
超级链接=新的超级链接();
link.NavigateUri=新Uri(word);
link.Inlines.Add(word);
link.Click+=新建路由EventHandler(link\u Click);
link.ToolTip=“在默认浏览器中打开链接”;
textblock.Inlines.Add(link);
}
抓住
{
//托多:我们在抓什么?为什么?记下来?
textblock.Inlines.Add(word);
}
}
//可点击@name
else if(word.StartsWith(“@”))
{
textblock=格式名(textblock,word);
}
//可点击的标签
else if(word.StartsWith(“#”)
{
string hashtag=string.Empty;
Match foundHashtag=Regex.Match(单词,@“#(\w+(.*));
if(foundHashtag.Success)
{
hashtag=foundHashtag.Groups[1]。捕获[0]。值;
超链接标记=新的超链接();
tag.Inlines.Add(hashtag);
字符串hashtagUrl=”http://search.twitter.com/search?q=%23{0}";
//主应用程序可以访问设置类,其中
//可以存储用户定义的hashtagUrl。此硬编码的
//用于设置NavigateUri只是一种默认行为
//如果由于某种原因未处理单击事件,将使用。
tag.NavigateUri=新Uri(String.Format(hashtagUrl,hashtag));
tag.ToolTip=“显示包含此标签的状态”;
tag.tag=hashtag;
tag.Click+=newroutedeventhandler(hashtag\u Click);
textblock.Inlines.Add(“#”);
textblock.Inlines.Add(标记);
textblock.Inlines.Add(foundHashtag.Groups[“后缀”]。捕获[0]。值);
}
}
其他的
{
textblock.Inlines.Add(word);
}
}
textblock.Inlines.Add(“”);
}
}
公共静态TweetTextBlock格式名(TweetTextBlock,字符串字)
{
string userName=string.Empty;
string firstLetter=word.Substring(0,1);
Match foundUsername=Regex.Match(单词,@“@(\w+(.*)”);
if(foundUsername.Success)
{
userName=foundUsername.Groups[1]。捕获[0]。值;
超链接名称=新建超链接();
name.Inlines.Add(用户名);
name.NavigateUri=新Uri(“http://twitter.com/“+用户名);
name.ToolTip=“查看@”+用户名+“”最近的推文”;
name.Tag=用户名;
name.Click+=newroutedeventhandler(name\u Click);
如果(第一个字母!=“@”)
textblock.Inlines.Add(第一个字母);
textblock.Inlines.Add(“@”);
textblock.Inlines.Add(名称);
textblock.Inlines.Add(foundUsername.Groups[“后缀”]。捕获[0]。值);
}
返回文本块;
}
静态无效链接\u单击(对象发送者,路由目标e)
{
尝试
{
System.Diagnostics.Process.Start(((超链接)sender.NavigateUri.ToString());
}
抓住
{
//TODO:导致错误的日志特定URL
Show(“启动指定的URL时出现问题。”,“错误”,MessageBoxButton.OK,MessageBoxImage.叹号);
}
}
}

}将链接单击方法更改为

static void link_click(Object sender, RequestNavigateEventArgs e) {
    try {
        System.Diagnostics.Process.Start(e.Uri.ToString());
    } catch {
        //TODO: Log specific URL that caused error
        MessageBox.Show("There was a problem launching the specified URL.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
    } finally {
       e.Handled = true;
    }
}
换衣服

link.Click+=new RoutedEventHandler(link_Click);

在link中设置
e.Handled=true
单击以标记您已处理链接单击以防止框架额外处理您的链接clic
link.Click+=new RoutedEventHandler(link_Click);
link.RequestNavigate+=new RequestNavigateEventHandler(link_Click);
    Process.Start((e.OriginalSource as Hyperlink).NavigateUri.ToString());
    e.Handled  = true;