【问题标题】:How to make button inside a stacklayout clickable but make the rest of the items and the stacklayout not clickable?如何使堆栈布局内的按钮可点击,但使其余项目和堆栈布局不可点击?
【发布时间】:2019-01-18 23:54:24
【问题描述】:

我有一个包含许多元素的堆栈布局,其中一个是按钮。我希望能够单击此按钮,但我希​​望其中的其他元素(以及 stacklayout 本身)为IsEnabled false。

此堆栈布局位于地图之上,因此用户可以在其之上使用地图的基本功能非常重要。

现在我有这样的东西(我已经删除了那里的所有属性以使代码更具可读性)

<StackLayout IsEnabled = "false" >
<Image />
<Label />
<Button Clicked = "ClickEvent" />
</StackLayout>

所以现在我将堆栈设置为IsEnabledfalse,这使得它在地图顶部时无法点击,这很好,但我现在无法点击我的按钮。

我该如何解决这个问题?

【问题讨论】:

标签: xamarin xamarin.forms


【解决方案1】:

尝试改用InputTransparent

设置 InputTransparent 只会禁用输入,而是将它们传递给视觉上位于元素后面的 VisualElement。

【讨论】:

  • 所以我会在所有元素(包括stacklayout)上将其设置为true,但不是按钮? (我会将其设置为 false)我现在正在尝试查看
  • 当我将stacklayouts inputtransparent设置为true并将其中的按钮设置为false时,该按钮无法点击。
【解决方案2】:

您不能只使用 XAML 元素的 z-index 吗?将其包装在另一个容器中(例如 StackLayoutGrid),如下所示:

<StackLayout>
    <StackLayout IsEnabled = "false" >
        <Image />
        <Label />
    </StackLayout>
    <Button Clicked = "ClickEvent" />
</StackLayout>

这将在StackLayout上方显示Button

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多