我有以下页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="PhotoManager.MainPage">
<ScrollView>
<VerticalStackLayout
Padding="5,0"
Spacing="10">
<Image
Source="banner2.jpg"
HeightRequest="75"
Aspect="AspectFit"
SemanticProperties.Description="Organize My League" />
<Line Stroke="Black" X2="{Binding Width, Source={RelativeSource Self}}" HorizontalOptions="Fill" StrokeThickness="2" />
<ActivityIndicator x:Name="activityIndicator"
IsVisible="false"
IsRunning="True"
Color="{StaticResource NavigationBarColor}" ZIndex="1000"
VerticalOptions="Center" HorizontalOptions="Center"
WidthRequest="100" HeightRequest="100"/>
<Label
Text="Log On"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label
Text="Username"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Enter your username." />
<Entry x:Name="TheUsername"
Placeholder="Enter Username"/>
<Label
Text="Password"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Enter your password." />
<Entry x:Name="ThePassword"
Placeholder="Enter Password"
IsPassword="true" />
<Button
x:Name="CounterBtn"
Text="Submit"
SemanticProperties.Hint="Log on"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
以下行:
<Line Stroke="Black" X2="{Binding Width, Source={RelativeSource Self}}" HorizontalOptions="Fill" StrokeThickness="2" />
生成主题警告。如何解决该警告?
如果你分手
Binding
,我们有Width
, // Width 从何而来?这就是 .NET 的想法Source={RelativeSource Self}
, // “自我是什么?”<Line ...
, // Aha Self == 行这意味着我们需要指定
x:DataType=Line
。从另一个角度来看,我们告诉 .NET 这Width
是线的宽度。也许,将来,优化的编译器可以推断出此信息,因为从您的代码片段可以明显看出
Width
来自Line
。Binding
然而,在更复杂的中,您将不得不帮助它,这就是x:DataType
目的。