Issue
I understand how this code works but can someone explain what the first line does? Is this translated some place into some C# code. How about if I wanted to code this manually, how could I go about that?
[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;
}
}
Solution
This attribute tells the XAML processor that if should use the Frame
's Content
property as the default basically. So, in practice it allows you to write this
<ContentView>
<Label Text="Hello, Forms"/>
</ContentView>
Instead of
<ContentView>
<ContentView.Content>
<Label Text="Hello, Forms"/>
</ContentView.Content>
</ContentView>
Examples taken from the Docs page.
In regard to your question "how do I write this in C#?" you don't. This is something specific to XAML and nothing more than syntactic sugar. In C# you would simply assign something to the Content
property. I.e.:
var frame = new Frame();
Frame.Content = new Label() { Text = "Hello, Forms" };
Answered By - Gerald Versluis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.