0

我正在使用带有 mvvm 模式的 Silverlight 5。在 xaml 页面中,我有一个超链接按钮和图像。如果我单击名为“预览”的按钮,则意味着必须在新选项卡浏览器中打开图像或任何文件。

XAML 代码:

<Image Source="{Binding Image}"/>
    <HyperlinkButton Content="Preview" Width="60" Height="26"   
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        TargetName="_blank"
        Name="HyperlinkButton"
        Background="Transparent"
        Click="HyperlinkButton_Click">
    </HyperlinkButton>

查看型号代码:

void ChooseHyperExecute(object param)
{
    WebBrowser br = new WebBrowser();
    SampleViewModel dt = param as SampleViewModel;

    string ma = dt.String_Value;
    br.Navigate(new Uri(Application.Current.Host.Source, string.Format("./Images/{0}", ma)));

}

但它不起作用。

4

1 回答 1

1

您需要使用HtmlWindow.Navigate方法:

void ChooseHyperExecute(object param)
{
    SampleViewModel dt = param as SampleViewModel;
    string ma = dt.String_Value;            
    var externalUri = new Uri(Application.Current.Host.Source, 
        string.Format("./Images/{0}", ma));
    var absoluteUri = new Uri(externalUri, UriKind.Absolute);
    System.Windows.Browser.HtmlPage.Window.Navigate(absoluteUri, "_blank");
}
于 2012-11-05T14:25:59.820 回答