我正在使用TextBox中的超链接向我的WPF应用程序添加一个链接:
<TextBlock Margin="480,92,460,713" Height="24">
<Hyperlink NavigateUri="{Binding MyLink}" RequestNavigate="Hyperlink_RequestNavigate">My Link</Hyperlink>
</TextBlock>绑定"MyLink“不起作用。我需要使用的链接有一个查询字符串,其中包含一个我需要在代码中动态更改的变量。如果我试图将链接硬编码到XAML中,我会得到一个错误,因为查询字符串中有一个带“与”符号的变量。
当我把它指向像google这样的网站时,我的链接就会起作用。但是我需要在c#代码中设置它,以便能够在查询字符串中设置我的变量。有没有办法做到这一点?谢谢!
发布于 2010-12-30 03:34:35
你所做的应该是有效的.
为了测试这一点,创建一个默认的WPF应用程序,并将以下代码放在Window1.xaml的Grid中...
<TextBlock>
<Hyperlink NavigateUri="{Binding}" RequestNavigate="Hyperlink_RequestNavigate">My Link</Hyperlink>
</TextBlock>...in Window1.xaml.cs添加这个...
public Window1()
{
InitializeComponent();
this.DataContext = "whatever the heck i want";
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
//e.Uri will display "whatever the heck i want"
//which would allow you to do whatever you want
//with the URL at that point
Process.Start(new ProcessStartInfo("url_you_want_to_use"));
e.Handled = true;
}https://stackoverflow.com/questions/4557136
复制相似问题