gpt4 book ai didi

xamarin - 如果未在使用模板的 XAML 中指定,我怎样才能使模板内的 HeightRequest 被忽略?

转载 作者:行者123 更新时间:2023-12-03 20:56:32 25 4
gpt4 key购买 nike

此模板将 HeaderHeight 作为绑定(bind)参数。如果在调用模板的 XAML 中未指定 HeaderHeight ,是否有办法让 StackLayout 忽略它?

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Japanese;assembly=Japanese" x:Class="Japanese.Templates.HeaderTemplate" x:Name="this">
<ContentView.Triggers>
<Trigger TargetType="local:Templates.HeaderTemplate" Property="HeaderType" Value="Custom">
<Setter Property="Content">
<Setter.Value>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" Spacing="0" Margin="0">
<StackLayout HeightRequest="{Binding HeaderHeight, Source={x:Reference this}}" Orientation="Vertical" Spacing="0" Margin="0" >
<Label Text="ABC" HorizontalOptions="Start" VerticalOptions="EndAndExpand" />
</StackLayout>
</StackLayout>
</Setter.Value>
</Setter>
</Trigger>
</ContentView.Triggers>
</ContentView>

最佳答案

您可以设置默认值HeaderHeight-1
UI应该恢复正常

HeaderHeight = -1;

一旦它是 BindableProperty ,它应该是这样的:
public static readonly BindableProperty HeaderHeightProperty = BindableProperty.Create(nameof(HeaderHeight), typeof(double), typeof(HeaderTemplate), -1);
public double HeaderHeight
{
get => (double)GetValue(HeaderHeightProperty);
set => SetValue(HeaderHeightProperty, value);
}

关于xamarin - 如果未在使用模板的 XAML 中指定,我怎样才能使模板内的 HeightRequest 被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52130529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com