【问题标题】:XAML Image Button some part not getting clickedXAML 图像按钮的某些部分没有被点击
【发布时间】:2013-03-22 04:42:00
【问题描述】:

我在 XAML 中有以下代码

<Button Tag='{Binding id}' Click="RecordClick">
                                            <Button.Template>
                                                <ControlTemplate>
                                                    <Image Source='./Images/RecordBG.png'  Height="270" Width="270" Margin='15,-5,0,0'/>
                                                </ControlTemplate>
                                            </Button.Template>
                                        </Button>

在 C# 背后的代码中:

private void RecordClick(object sender, RoutedEventArgs e)
        {
            string buttonName = (string)((Button)sender).Tag;

            this.Frame.Navigate(typeof(QRChart),buttonName);
        }

当我单击图像按钮时,某些部分没有被单击。有些部分只是工作。我想知道为什么会发生这种情况以及如何解决这个问题?

【问题讨论】:

  • Marco 的回答应该有效,但要了解您遇到问题的原因,您的图像的一部分是否透明?

标签: c# xaml click imagebutton


【解决方案1】:

我为图像顶部的Texblocks 添加了Tapped 事件。现在它按预期工作了。

【讨论】:

    【解决方案2】:

    尝试将演示者包装在具有设置背景的 Border 元素中。

    <ControlTemplate TargetType="{x:Type Button}">
        <Border Background="{TemplateBinding Background}">
        </Border>
    </ControlTemplate>
    

    喜欢:

        <Button Tag='{Binding id}' Click="RecordClick">
            <Button.Template>
                <ControlTemplate>
                    <Border Background="image here"/></Border>
                </ControlTemplate>
             </Button.Template>
        </Button>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-02
    • 2023-03-31
    • 1970-01-01
    • 2019-05-20
    • 2012-11-17
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多