本文整理汇总了C#中Xamarin.Forms.Grid类的典型用法代码示例。如果您正苦于以下问题:C# Grid类的具体用法?C# Grid怎么用?C# Grid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Grid类属于Xamarin.Forms命名空间,在下文中一共展示了Grid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrderPageCode
public OrderPageCode ()
{
Title = "Order Page - Code";
var grid = new Grid {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Padding = new Thickness (15)
};
for (int x = 0; x < 7; x++) {
grid.RowDefinitions.Add (new RowDefinition{ Height = new GridLength(50) });
}
grid.ColumnDefinitions.Add (new ColumnDefinition{ Width = new GridLength(90) });
grid.ColumnDefinitions.Add (new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) });
grid.Children.Add (new Label { Text = "Purchaser's Name:" }, 0, 0);
grid.Children.Add (new Label { Text = "Billing Address:" }, 0, 1);
grid.Children.Add (new Label { Text = "Tip:", FontAttributes = FontAttributes.Bold }, 0, 2);
grid.Children.Add (new Label { Text = "Phone Number:" }, 0, 3);
grid.Children.Add (new Label { Text = "Comments:" }, 0, 4);
grid.Children.Add (new Entry { Placeholder = "Full Name on Card" }, 1, 0);
grid.Children.Add (new Editor (), 1, 1);
grid.Children.Add (new Entry{ Keyboard = Keyboard.Numeric }, 1, 2);
grid.Children.Add (new Entry { Keyboard = Keyboard.Telephone }, 1, 3);
grid.Children.Add (new Editor (), 1, 4);
var fstring = new FormattedString ();
fstring.Spans.Add (new Span { Text = "Wait! ", ForegroundColor = Color.Red });
fstring.Spans.Add (new Span { Text = "Please double check that everything is right." });
grid.Children.Add (new Label { FormattedText = fstring }, 1, 5);
grid.Children.Add (new Button { TextColor = Color.White, BackgroundColor = Color.Gray, Text = "Save" }, 1, 6);
Content = grid;
}
示例2: HomePageCS
public HomePageCS ()
{
var label = new Label {
Text = "Label Shadow Effect",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
label.Behaviors.Add (new EffectBehavior {
Group = "Xamarin",
Name = "LabelShadowEffect"
});
Content = new Grid {
Padding = new Thickness (0, 20, 0, 0),
Children = {
new Label {
Text = "Effects Demo with a Behavior",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
},
label
}
};
}
示例3: SliderLabels
private Grid SliderLabels()
{
var grid = new Grid {
HorizontalOptions = LayoutOptions.FillAndExpand,
ColumnDefinitions = {
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
}
};
grid.Children.Add (
SyncLabel ("1", LayoutOptions.StartAndExpand, new Thickness (5, 0, 0, 0))
, 0, 0);
grid.Children.Add (
SyncLabel ("5", LayoutOptions.Center)
, 1, 0);
grid.Children.Add (
SyncLabel ("30", LayoutOptions.Center)
, 2, 0);
grid.Children.Add (
SyncLabel ("60", LayoutOptions.EndAndExpand, new Thickness (0, 0, 5, 0))
, 3, 0);
return grid;
}
示例4: FeedOverview
public FeedOverview()
{
var refreshButton = new Button {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Text = "Refresh"
};
refreshButton.SetBinding(Button.CommandProperty, "RefreshCommand");
var template = new DataTemplate(typeof(TextCell));
// We can set data bindings to our supplied objects.
template.SetBinding(TextCell.TextProperty, "Title");
template.SetBinding(TextCell.DetailProperty, "Description");
var listView = new ListView {ItemTemplate = template};
listView.SetBinding(ListView.ItemsSourceProperty, "FeedItems");
// Push the list view down below the status bar on iOS.
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
Content = new Grid {
BindingContext = new FeedReaderViewModel(),
RowDefinitions = new RowDefinitionCollection {
new RowDefinition { Height = new GridLength (1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength (0, GridUnitType.Auto) },
},
Children = {
new ViewWithGridPosition(listView, 0,0),
new ViewWithGridPosition(refreshButton, 1,0)
},
};
}
示例5: BaseAsyncActivityTemplate
public BaseAsyncActivityTemplate() {
// Adds the Content Presenter
var contentPresenter = new ContentPresenter();
Children.Add(contentPresenter, 0, 0);
// The overlay that is presented when an Activity is Running
var overlayGrid = new Grid { BackgroundColor = Color.FromHex("#CCCCCCCC") };
overlayGrid.SetBinding(IsVisibleProperty, new TemplateBinding("IsActivityRunning"));
var descriptionLabel = new Label { TextColor = Color.White };
descriptionLabel.SetBinding(Label.TextProperty, new TemplateBinding("ActivityDescription"));
var activityIndicator = new ActivityIndicator { Color = Color.White };
activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new TemplateBinding("IsActivityRunning"));
// A layout to hold the Activity Indicator and Description
var activityIndicatorLayout = new StackLayout {
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};
activityIndicatorLayout.Children.Add(activityIndicator);
activityIndicatorLayout.Children.Add(descriptionLabel);
// Finally add the indicator to the overlay and the overlay to the grid
overlayGrid.Children.Add(activityIndicatorLayout, 0, 0);
Children.Add(overlayGrid);
}
示例6: GridPage5
public GridPage5 ()
{
Padding = new Thickness (0, Device.OnPlatform (20, 0, 0), 0, 0);
var grid = new Grid ();
grid.Children.Add (
new Image() {
Source= Device.OnPlatform("[email protected]", "icon.png", "")
}, 0, 0);
grid.Children.Add (new Label () { Text = "40", BackgroundColor = Color.Yellow}, 0, 1);
grid.Children.Add (new Label () { Text = "Remainder", BackgroundColor = Color.Pink}, 0, 2);
grid.RowDefinitions.Add (new RowDefinition ()
{
Height = new GridLength(1, GridUnitType.Auto)
});
grid.RowDefinitions.Add (new RowDefinition ()
{
Height = new GridLength(40, GridUnitType.Absolute)
});
grid.RowDefinitions.Add (new RowDefinition ()
{
Height = new GridLength(1, GridUnitType.Star)
});
Content = grid;
}
示例7: GridLayoutPage
public GridLayoutPage()
{
var layout = new StackLayout
{
Orientation = StackOrientation.Vertical,
Padding = 20
};
var grid = new Grid
{
RowSpacing = 50
};
grid.Children.Add(new Label { Text = "This" }, 0, 0); // Left, First element
grid.Children.Add(new Label { Text = "text is" }, 1, 0); // Right, First element
grid.Children.Add(new Label { Text = "in a" }, 0, 1); // Left, Second element
grid.Children.Add(new Label { Text = "grid!" }, 1, 1); // Right, Second element
var gridButton = new Button { Text = "So is this Button!\nClick me." };
gridButton.Clicked += delegate
{
gridButton.Text = string.Format("Thanks! {0} clicks.", count++);
};
layout.Children.Add(grid);
layout.Children.Add (gridButton);
Content = layout;
}
示例8: OnAppearing
protected override void OnAppearing()
{
base.OnAppearing();
if (BindingContext == null)
{
BindingContext = _project;
var grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = 150 });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.VerticalOptions = LayoutOptions.StartAndExpand;
grid.Children.Add(new Label { Text = "Name" }, 0, 0);
var editor = new Editor();
editor.SetBinding(Editor.TextProperty, "Name");
grid.Children.Add(editor, 1, 0);
label.IsVisible = false;
label.Text = "Error in value";
label.TextColor = Color.Red;
grid.Children.Add(label, 1, 1);
grid.Children.Add(new Label { Text = "Description" }, 0, 2);
grid.Children.Add(new Editor { Text = _project.Description }, 1, 2);
grid.Children.Add(new Label { Text = "Started" }, 0, 3);
grid.Children.Add(new Editor { Text = _project.Started.HasValue ? _project.Started.GetValueOrDefault().ToShortDateString() : string.Empty }, 1, 3);
grid.Children.Add(new Label { Text = "Ended" }, 0, 4);
grid.Children.Add(new Editor { Text = _project.Ended.HasValue ? _project.Ended.GetValueOrDefault().ToShortDateString() : string.Empty }, 1, 4);
Content = grid;
}
}
示例9: HomePage
/// <summary>
/// Constructor
/// </summary>
public HomePage()
{
BackgroundImage = "bg.png";
var masterLayout = new StackLayout {
Orientation = StackOrientation.Vertical,
Spacing = 10
};
// Start Button
var startButton = new Button { Text = "スタート", HorizontalOptions = LayoutOptions.Center };
masterLayout.Children.Add(startButton);
// Text followed by two auto expanding text areas
var row = new StackLayout { Orientation = StackOrientation.Horizontal, Spacing = 10, Padding = new Thickness(10, 0, 10, 0) };
row.Children.Add(new Label { Text = "範囲:" });
masterLayout.Children.Add(row);
var grid = new Grid();
grid.HorizontalOptions = LayoutOptions.FillAndExpand;
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
var lowerBoundField = new Entry();
var upperBoundField = new Entry();
grid.Children.Add(lowerBoundField, 0, 0);
grid.Children.Add(upperBoundField, 1, 0);
row.Children.Add(grid);
// Data binding
upperBoundField.SetBinding(Entry.TextProperty, new Binding("UpperBoundText", BindingMode.TwoWay));
lowerBoundField.SetBinding(Entry.TextProperty, new Binding("LowerBoundText", BindingMode.TwoWay));
startButton.SetBinding(Button.CommandProperty, new Binding("StartPracticeCommand", BindingMode.OneWay));
Content = masterLayout;
}
示例10: HomePageCS
public HomePageCS ()
{
label = new Label {
Text = "Label Shadow Effect",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
ShadowEffect.SetHasShadow (label, true);
ShadowEffect.SetColor (label, Device.OnPlatform (Color.Black, Color.White, Color.White));
ShadowEffect.SetRadius (label, 5);
ShadowEffect.SetDistanceX (label, 5);
ShadowEffect.SetDistanceY (label, 5);
var button = new Button { Text = "Change Shadow Color", VerticalOptions = LayoutOptions.EndAndExpand };
button.Clicked += OnButtonClicked;
Content = new Grid {
Padding = new Thickness (0, 20, 0, 0),
Children = {
new Label {
Text = "Effects Demo",
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
},
label,
button
}
};
}
示例11: App
public App()
{
_grid = new Grid {
BackgroundColor = Color.Purple, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand
};
// THIS BOX VIEW DOES NOT SHOW UP IF YOU RE-SIZE THE ROW DEFINITION
var boxView = new BoxView { BackgroundColor = Color.Blue, VerticalOptions = LayoutOptions.End };
var button = new Button
{
Text = "button",
BackgroundColor = Color.Lime,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
button.Clicked += (sender, e) =>
{
_grid.RowDefinitions[1].Height = Math.Abs(_grid.RowDefinitions[1].Height.Value - 100) < double.Epsilon ?
new GridLength(0) : new GridLength(100);
};
Grid.SetRow(boxView, 1);
_grid.RowDefinitions.Add(new RowDefinition() { Height = 100 });
_grid.RowDefinitions.Add(new RowDefinition() { Height = 0 }); // CHANGE THIS TO 100 and it works fine
_grid.Children.Add(boxView);
_grid.Children.Add(button);
MainPage = new ContentPage { Content = _grid };
}
示例12: GridExample2
public GridExample2 ()
{
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
//RowSpacing = 20,
//ColumnSpacing = 20,
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = new GridLength(200, GridUnitType.Absolute) },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto }
},
ColumnDefinitions =
{
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition { Width = GridLength.Auto }
}
};
grid.Children.Add(new Label
{
Text = "I'm at 0,0",
FontSize = 30,
FontAttributes = FontAttributes.Bold,
}, 0, 0);
grid.Children.Add(new Label
{
Text = "Me? 1, 1",
FontSize = 30,
FontAttributes = FontAttributes.Bold,
TextColor = Color.Black,
BackgroundColor = Color.Lime
}, 1, 1);
grid.Children.Add(new Label
{
Text = "2, 2 here",
FontSize = 25,
FontAttributes = FontAttributes.Bold,
TextColor = Color.White,
BackgroundColor = Color.Red
}, 2, 2);
grid.Children.Add(new Label
{
Text = "I'm at 0,3",
FontSize = 30,
FontAttributes = FontAttributes.Bold
}, 0, 3);
// Padding on edges and a bit more for iPhone top status bar
this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
this.Content = grid;
}
示例13: FlowListViewInternalCell
public FlowListViewInternalCell(FlowListView flowListView)
{
this.flowListView = flowListView;
root = new Grid() {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
RowSpacing = 0f,
ColumnSpacing = 0f,
Padding = 0f,
RowDefinitions = new RowDefinitionCollection() {
new RowDefinition() { Height = GridLength.Auto }
},
ColumnDefinitions = new ColumnDefinitionCollection()
};
for (int i = 0; i < this.flowListView.FlowColumnsDefinitions.Count; i++)
{
root.ColumnDefinitions.Add(new ColumnDefinition() {
Width = new GridLength(1, GridUnitType.Star)
});
}
View = root;
}
示例14: FlowListViewInternalCell
/// <summary>
/// Initializes a new instance of the <see cref="DLToolkit.Forms.Controls.FlowListViewInternalCell"/> class.
/// </summary>
/// <param name="flowListViewRef">Flow list view reference.</param>
public FlowListViewInternalCell(WeakReference<FlowListView> flowListViewRef)
{
_flowListViewRef = flowListViewRef;
FlowListView flowListView = null;
flowListViewRef.TryGetTarget(out flowListView);
_useGridAsMainRoot = !flowListView.FlowUseAbsoluteLayoutInternally;
if (!_useGridAsMainRoot)
{
_rootLayout = new AbsoluteLayout()
{
Padding = 0d,
BackgroundColor = flowListView.FlowRowBackgroundColor,
};
View = _rootLayout;
}
else
{
_rootLayoutAuto = new Grid()
{
RowSpacing = 0d,
ColumnSpacing = 0d,
Padding = 0d,
BackgroundColor = flowListView.FlowRowBackgroundColor,
};
View = _rootLayoutAuto;
}
_flowColumnTemplate = flowListView.FlowColumnTemplate;
_desiredColumnCount = flowListView.DesiredColumnCount;
_flowColumnExpand = flowListView.FlowColumnExpand;
}
示例15: LeagueCardView
public LeagueCardView(LeagueItem context)
{
BindingContext = context;
Grid grid = new Grid {
Padding = new Thickness(1,1,2,2),
RowSpacing = 0,
ColumnSpacing = 0,
BackgroundColor = Color.FromHex ("E3E3E3").MultiplyAlpha(0.5),
RowDefinitions = {
new RowDefinition { Height = new GridLength (100, GridUnitType.Absolute) }
},
ColumnDefinitions = {
new ColumnDefinition { Width = new GridLength (4, GridUnitType.Absolute) },
new ColumnDefinition {
}
}
};
grid.Children.Add (
new FixtureCardStatusView ()
,0,0);
grid.Children.Add (new LeagueCardDetailsView (LeagueItem), 1, 0);
var tgr = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
tgr.Tapped += (sender, args) => {
OnCardClicked?.Invoke (LeagueItem);
};
grid.GestureRecognizers.Add (tgr);
Content = grid;
}