【问题标题】:Why is my Label not Visible inside Frame in Xamarin Forms?为什么我的标签在 Xamarin 表单中的框架内不可见?
【发布时间】:2018-08-06 22:11:10
【问题描述】:

我正在尝试为 Xamarin 表单中的标签创建简单的黑色边框。似乎框架内的任何东西都是不可见的。

这是我的代码:

<Frame BorderColor="Black"   
       CornerRadius="0">
    <Label x:Name="txtText"
           Text="Here"
               TextColor="Black"
               BackgroundColor="White"
               HorizontalOptions="FillAndExpand"
               VerticalOptions="FillAndExpand"
               HorizontalTextAlignment="Center" />
</Frame>

我可以将我框架中的背景属性设置为任何东西,并且效果很好,我什至尝试将其设置为透明但没有成功。

这是我在上面的代码中看到的。

如果有帮助,我正在使用 Visual Studio 2017 和 Android。

更新

我找到了一个解决方案,但它看起来很老套。我已经把它全部放在了一个 StackLayout 中,将框架的请求高度设置为 100,并将填充设置为 1。

这是更新后的代码:

<StackLayout>
    <Frame BorderColor="{DynamicResource PrimaryColour}"   
           CornerRadius="0"
           Padding="1"
           HeightRequest="100">
        <Label x:Name="txtText"
               Text="Here"
               TextColor="{DynamicResource PrimaryColour}"
               BackgroundColor="{DynamicResource SecondaryColour}"
               HorizontalTextAlignment="Center"
               VerticalTextAlignment="Center"/>
    </Frame>
</StackLayout>

【问题讨论】:

  • 尝试将颜色设置为不同的显式值,以验证它不是您的资源定义的问题
  • 我用硬编码的颜色更新了问题。我得到了同样的结果。
  • @Noobie3001 这是嵌入到网格中的吗?
  • 在 ContentView 中。我来自 WPF 世界,是 Xamarin 的新手。我试图创建一个自定义用户控件(自定义按钮)。我认为文档说要使用 ContentView,但不能确定。
  • 你也可以试试这个,而不是在Frame中使用Border Color尝试在Stack Layout中使用`BackgroundColor="Black"`和Padding="1",并删除框架。跨度>

标签: android visual-studio xamarin xamarin.forms


【解决方案1】:

Frame 采用 20 的默认填充,所以如果 frame 真的很小,那么它里面的元素将永远不会显示。 所以,只需padding="0"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2017-05-10
    • 2019-06-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多