简体   繁体   English

Windows Phone 8图像超链接

[英]Windows Phone 8 Image Hyperlink

I started to develop some apps for WP8 and I have one question. 我开始为WP8开发一些应用程序,但我有一个问题。 so that's what i want to do: create a new button on xaml mainpage file. 所以这就是我想要做的:在xaml主页文件上创建一个新按钮。 and when on click="butt1_Click" to show a new messagebox or something like this(maybe a new StackPanel) that will contain: 并在click =“ butt1_Click”上显示新的消息框或类似内容(可能是新的StackPanel)时,其中包含:

Item 1 , Item 2, Item 3.... I will try to explain this in xaml and if someone can transform the code in C#.. 第1项,第2项,第3项...。​​我将尝试在xaml中解释这一点,以及是否有人可以在C#中转换代码。

    <Hyperlink 
Content="Item 1" Name="HyperlinkImage"
FontSize="18" Width="175" Height="75" 
Margin="140,350,140,185" NavigateUri="/Assets/myimage.png/"/>

I will explain this in HTML, maybe that way someone will understand what I want to do: 我将用HTML解释这一点,也许有人会理解我想做的事情:

<a href="/Assets/myimage.png/"> Item 1 </a>

Thanks Alot! 非常感谢!

Here's a little image on what I'm plaining to do: http://img12.imageshack.us/img12/5769/zylk.jpg 这是我要执行的操作的一张小图片: http ://img12.imageshack.us/img12/5769/zylk.jpg

Try something like this: 尝试这样的事情:

On MainPage.xaml add: 在MainPage.xaml上添加:

<StackPanel>
    <Button Content="Image 1" Tag="/Assets/AlignmentGrid.png" Click="ImageButtonClicked" />
    <Button Content="Image 2" Tag="/Assets/ApplicationIcon.png" Click="ImageButtonClicked" />
    <Button Content="Image 3" Tag="/Assets/Tiles/FlipCycleTileMedium.png" Click="ImageButtonClicked" />
</StackPanel>

(Note that all buttons have the same event handler) (请注意,所有按钮都具有相同的事件处理程序)

In MainPage.xaml.cs add: 在MainPage.xaml.cs中添加:

private void ImageButtonClicked(object sender, RoutedEventArgs e)
{
    NavigationService.Navigate(
        new Uri("/ImagePage.xaml?path=" + 
                HttpUtility.UrlEncode((sender as Button).Tag.ToString()),
                UriKind.Relative));
}

Add a page ImagePage.xaml and add the following to it: 添加页面ImagePage.xaml并添加以下内容:

<Image x:Name="TheImage" />

Then in ImagePage.xaml.cs 然后在ImagePage.xaml.cs中

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string path = "";

    if (NavigationContext.QueryString.TryGetValue("path", out path))
    {
        if (!string.IsNullOrWhiteSpace(path))
        {
            this.TheImage.Source =
                new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
        }
    }
}

This lets you define in the XAML the image to show on a separate page when the button is clicked. 这使您可以在XAML中定义当单击按钮时在单独的页面上显示的图像。
Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM