我理解这段代码是如何工作的,但是有人能解释一下第一行是做什么的吗?这是不是翻译成了一些C#代码。如果我想手动编写代码,我该怎么做呢?
[Xamarin.Forms.ContentProperty("Contents")]
class PopupFrame : Frame
{
StackLayout contentStack { get; } = new StackLayout();
public IList<View> Contents { get => contentStack.Children; }
public PopupFrame()
{
Content = contentStack;
HasShadow = true;
HorizontalOptions = LayoutOptions.FillAndExpand;
Padding = 0;
VerticalOptions = LayoutOptions.Center;
}
}发布于 2020-12-22 16:33:35
这个属性告诉XAML处理器,if基本上应该使用Frame的Content属性作为默认值。
<ContentView>
<Label Text="Hello, Forms"/>
</ContentView>而不是
<ContentView>
<ContentView.Content>
<Label Text="Hello, Forms"/>
</ContentView.Content>
</ContentView>取自Docs page的示例。
关于你的问题“我如何用C#写这篇文章?”这是XAML特有的东西,只不过是语法上的糖而已。在C#中,只需给Content属性赋值即可。即:
var frame = new Frame();
Frame.Content = new Label() { Text = "Hello, Forms" };https://stackoverflow.com/questions/65403844
复制相似问题