Вопрос Xamarin.Forms разработчикам
Вопрос Xamarin.Forms разработчикам:
Вы действительно так разрабатываете UI? — т.е. это допустимо так страниц 100 в C# сделать, или такой код для UI идет сразу в «корзину» как очень некачественная и крайне неудобная для дальнейшей поддержки работа?
namespace Sample
{
public class Page1 : BaseContentPage<Page1ViewModel>
{
public Page1()
{
var grid = new Grid
{
Padding = new Thickness(0, 20, 0, 0),
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = 100 },
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = 50 },
},
ColumnDefinitions = new ColumnDefinitionCollection
{
new ColumnDefinition { Width = GridLength.Star },
new ColumnDefinition { Width = 100 }
}
};
var questionLabel = new Label
{
Text = "Some text...",
FontAttributes = FontAttributes.Bold,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.WordWrap,
Margin = new Thickness(15, 0, 15, 0)
};
var answerEditor = new Editor
{
Margin = new Thickness(20, 0, 20, 0),
BackgroundColor = Color.White
};
var nextButton = new Button
{
Text = "Next",
BorderRadius = 5,
BackgroundColor = Color.Green,
TextColor = Color.White,
};
var dotsControl = new ContentView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.White,
HeightRequest = 50,
Margin = new Thickness(0, 0, 0, 0)
};
grid.Children.Add(questionLabel, 0, 2, 0, 1);
grid.Children.Add(answerEditor, 0, 2, 1, 2);
grid.Children.Add(nextButton, 1, 2, 2, 3);
grid.Children.Add(dotsControl, 0, 2, 4, 5);
Content = grid;
BackgroundColor = Color.FromRgb(225, 225, 225);
answerEditor.SetBinding(Editor.TextProperty, nameof(Page1ViewModel.AnswerText));
nextButton.SetBinding(Button.CommandProperty, nameof(Page1ViewModel.NextButtonCommand));
}
}
}
3 коментарі
Додати коментар Підписатись на коментаріВідписатись від коментарів