将图片的一部分设置为按钮
Set part of a picture as button
我有一张较大的图片,我只想将该图片的一小部分(该部分位于图片的中心)用作按钮,即可以点击。这可能吗?
只需添加一些透明元素,例如矩形。然后处理 Tap 事件。这是我的例子:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/Image.jpg"/>
</Grid.Background>
<Rectangle Width="48"
Height="48"
Fill="Transparent"
Tap="Rectangle_Tap" />
</Grid>
这就是它在 Visual Studio 中的样子:
小矩形是不可见的,但用户可以点击它。
请注意,在 Windows Phone 中,如果控件是透明的或将不透明度设置为 0,它仍会对用户输入做出反应。
我有一张较大的图片,我只想将该图片的一小部分(该部分位于图片的中心)用作按钮,即可以点击。这可能吗?
只需添加一些透明元素,例如矩形。然后处理 Tap 事件。这是我的例子:
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/Image.jpg"/>
</Grid.Background>
<Rectangle Width="48"
Height="48"
Fill="Transparent"
Tap="Rectangle_Tap" />
</Grid>
这就是它在 Visual Studio 中的样子:
小矩形是不可见的,但用户可以点击它。 请注意,在 Windows Phone 中,如果控件是透明的或将不透明度设置为 0,它仍会对用户输入做出反应。