image map in WPF

2019-08-06 07:35发布

问题:

I have a splashscreen that contains an image, and when you click it it closes, like:

<Canvas MouseLeftButtonUp="Image_MouseLeftButtonUp"> 
        <Canvas.Background>
            <ImageBrush ImageSource="pack://application:,,,/S3.ParametersUE.About;component/Resources/splash.jpg" />
        </Canvas.Background>
</Canvas>

Now, in the image there's also some text like 'http://www.site.com'

Is there a way in WPF to make this part clickable, so that when it's clicked, the web page opens in the browser; so basically the same behavior as an image map?

回答1:

Any chance you can remove the text from the Image itself, and just position a Button styled as a HyperLink inside the Canvas? It would give you better control over the font, text, and link. For example, if the link ever changes you can just modify the XAML instead of recreating the image.

The only other alternative I can think of is tracking MouseMove and MouseClick events on the Canvas and if the mouse is within specific coordinates of the Canvas then change cursor and process the click event.