Skip to main content
 首页 » 编程设计

c#之有什么方法可以在 XAML 上制作图像映射吗

2024年02月20日13虾米姐

我想使用 C# 和 XAML 创建一个 Windows 8 应用程序。

我想要一个图像的不同部分都可以点击,就像在 HTML 中使用图像映射元素一样。

可能有一种方法可以对单个图像执行此操作,但很难正确定位它们。

那么是否可以在 XAML 中使图像可点击?

请您参考如下方法:

xaml 中的简单概念示例...

添加命名空间 ;)

 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
 xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
 
 
<Grid Height="300" Width="300"> 
       <Grid.Background> 
         <Image/> <!-- Add your image source here,  
                       you dont want to know the picture I was going to put :) --> 
       </Grid.Background> 
 
       <Rectangle Height="20" Width="20" Stroke="Red" StrokeThickness="2" Margin="60,120"> 
         <i:Interaction.Triggers> 
           <!-- Couldn't recall if its "Click" event or "MouseLeftButtonDown" --> 
             <i:EventTrigger EventName="MouseLeftButtonDown"> 
                <ei:ChangePropertyAction TargetName="Blah" 
                                         PropertyName="Visibility" 
                                         Value="Visible" /> 
             </i:EventTrigger> 
         </i:Interaction.Triggers> 
       </Rectangle> 
 
       <TextBlock Text="Whoa Dude, Where's my click?" x:Name="Blah" FontSize="50" Visibility="Collapsed"/> 
 
    </Grid>