本文整理汇总了C#中Xamarin.Forms.Button类的典型用法代码示例。如果您正苦于以下问题:C# Button类的具体用法?C# Button怎么用?C# Button使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于Xamarin.Forms命名空间,在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePage
ContentPage CreatePage (Color backgroundColor)
{
_index++;
var button = new Button () {
Text = "next Page",
};
button.Clicked += (sender, e) => {
var page = CreatePage (Color.Green);
_navigationPage.PushAsync (page);
};
var contentPage = new ContentPage () {
Content = new StackLayout () {
BackgroundColor = backgroundColor,
VerticalOptions = LayoutOptions.Fill,
Children = {
new Label () {
Text = "page " + _index,
},
}
}
};
return contentPage;
}
示例2: MyControls
public MyControls ()
{
Title = "My First Xamarin.Forms";
var label = new Label {
Text = "Custom label",
Font = Font.SystemFontOfSize (20),
TextColor = Color.Aqua,
BackgroundColor = Color.Gray,
IsVisible = true,
LineBreakMode = LineBreakMode.WordWrap
};
var button = new Button { Text = "Click Me!" };
int i = 1;
button.Clicked += (s, e) => button.Text = "You clicked me: " + i++;
button.Clicked += (s, e) => Navigation.PushAsync(new MySecondPage());
Content = new StackLayout {
Spacing = 10,
VerticalOptions = LayoutOptions.Center,
Children = {
label,
button
}
};
}
示例3: ScriptInputGroupPage
public ScriptInputGroupPage(InputGroup inputGroup, List<InputGroup> previousInputGroups)
{
Title = "Input Group";
StackLayout contentLayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.FillAndExpand
};
foreach (StackLayout stack in UiProperty.GetPropertyStacks(inputGroup))
contentLayout.Children.Add(stack);
Button editInputsButton = new Button
{
Text = "Edit Inputs",
FontSize = 20,
HorizontalOptions = LayoutOptions.FillAndExpand
};
editInputsButton.Clicked += async (o, e) =>
{
await Navigation.PushAsync(new ScriptInputsPage(inputGroup, previousInputGroups));
};
contentLayout.Children.Add(editInputsButton);
Content = new ScrollView
{
Content = contentLayout
};
}
示例4: ProductImagePage
public ProductImagePage(ImageSource productImageSource)
{
Padding = Device.OnPlatform(new Thickness(0, 20, 0, 0), new Thickness(0), new Thickness(0));
_productImageSource = productImageSource;
BackgroundColor = Color.FromRgba(0, 0, 0, 127);
var absoluteLayout = new AbsoluteLayout
{
VerticalOptions = LayoutOptions.FillAndExpand
};
var closeButtom = new Button
{
WidthRequest = 50,
Image = "backspace.png",
BackgroundColor = Color.Transparent
};
closeButtom.Clicked += OnCloseButtonClicked;
var image = new Image
{
Source = _productImageSource
};
AbsoluteLayout.SetLayoutFlags(closeButtom, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(closeButtom, new Rectangle(1f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
AbsoluteLayout.SetLayoutFlags(image, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(image, new Rectangle(0.5f, 0.5f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
absoluteLayout.Children.Add(image);
absoluteLayout.Children.Add(closeButtom);
Content = absoluteLayout;
}
示例5: HomePageCS
public HomePageCS ()
{
var rotateButton = new Button { Text = "Rotate Animation" };
rotateButton.Clicked += OnRotateAnimationButtonClicked;
var relativeRotateButton = new Button { Text = "Relative Rotate Animation" };
relativeRotateButton.Clicked += OnRelativeRotateAnimationButtonClicked;
var rotateAnchorButton = new Button { Text = "Rotate Animation with Anchors" };
rotateAnchorButton.Clicked += OnRotateAnimationWithAnchorsButtonClicked;
var multipleRotateButton = new Button { Text = "Multiple Rotations" };
multipleRotateButton.Clicked += OnMultipleRotationAnimationButtonClicked;
var scaleButton = new Button { Text = "Scale Animation" };
scaleButton.Clicked += OnScaleAnimationButtonClicked;
var relativeScaleButton = new Button { Text = "Relative Scale Animation" };
relativeScaleButton.Clicked += OnRelativeScaleAnimationButtonClicked;
var transformButton = new Button { Text = "Transform Animation" };
transformButton.Clicked += OnTransformAnimationButtonClicked;
var fadeButton = new Button { Text = "Fade Animation" };
fadeButton.Clicked += OnFadeAnimationButtonClicked;
Title = "Basic Animation Demo";
Content = new StackLayout {
Margin = new Thickness (0, 20, 0, 0),
Children = {
rotateButton,
relativeRotateButton,
rotateAnchorButton,
multipleRotateButton,
scaleButton,
relativeScaleButton,
transformButton,
fadeButton
}
};
}
示例6: Pagina1
public Pagina1()
{
Label texto = new Label {
Text = "Página 1",
TextColor = Color.Blue
};
Button boton = new Button
{
Text = "Click para navegar a la página DOS"
};
boton.Clicked += (sender, e) => {
this.Navigation.PushAsync(new Pagina2());
};
//Stacklayout permite apilar los controles verticalmente
StackLayout stackLayout = new StackLayout
{
Children =
{
texto,
boton
}
};
//Como esta clase hereda de ContentPage, podemos usar estas propiedades directamente
this.Content = stackLayout;
this.Padding = new Thickness (5, Device.OnPlatform (20, 5, 5), 5, 5);
}
示例7: RequiredFieldTriggerPage
public RequiredFieldTriggerPage ()
{
var l = new Label {
Text = "Entry requires length>0 before button is enabled",
};
l.FontSize = Device.GetNamedSize (NamedSize.Small, l);
var e = new Entry { Placeholder = "enter name" };
var b = new Button { Text = "Save",
HorizontalOptions = LayoutOptions.Center
};
b.FontSize = Device.GetNamedSize (NamedSize.Large ,b);
var dt = new DataTrigger (typeof(Button));
dt.Binding = new Binding ("Text.Length", BindingMode.Default, source: e);
dt.Value = 0;
dt.Setters.Add (new Setter { Property = Button.IsEnabledProperty, Value = false });
b.Triggers.Add (dt);
Content = new StackLayout {
Padding = new Thickness(0,20,0,0),
Children = {
l,
e,
b
}
};
}
示例8: InitialPage
public InitialPage()
{
BindingContext = new InitialPageModel (this.Navigation);
Title = "Welcome to Peter";
Label timeLabel = new Label {
HorizontalOptions = LayoutOptions.Center,
};
timeLabel.SetBinding<InitialPageModel> (Label.TextProperty, vm => vm.DrinkingHoursDisplay);
Slider timeSlider = new Slider (1, 24, 5) {
HorizontalOptions = LayoutOptions.FillAndExpand,
};
timeSlider.SetBinding<InitialPageModel> (Slider.ValueProperty, vm => vm.DrinkingHours, BindingMode.TwoWay);
Button pressMe = new Button {
Text = "Help Peter",
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
FontSize = 60,
HeightRequest = 200,
BackgroundColor = Color.Yellow,
};
pressMe.SetBinding<InitialPageModel> (Button.CommandProperty, vm => vm.PressMeCommand);
Content = new StackLayout {
Children = {
timeLabel,
timeSlider,
pressMe,
}
};
}
示例9: App
public App()
{
var btnCs = new Button()
{
Text = "Abas Code Only"
};
btnCs.Clicked += btnCs_Clicked;
var btnXaml = new Button()
{
Text = "Abas XAML"
};
btnXaml.Clicked += btnXaml_Clicked;
// The root page of your application
MainPage = new NavigationPage(new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Abra uma das Telas"
},
btnCs,
btnXaml
}
}
});
}
示例10: Page2
public Page2()
{
var label = new Label { Text = "Hello ContentPage 2" };
Device.OnPlatform(
iOS: () => {
var parentTabbedPage = this.ParentTabbedPage() as MainTabbedPage;
if (parentTabbedPage != null) {
// HACK: get content out from under status bar if a navigation bar isn't doing that for us already.
Padding = new Thickness(Padding.Left, Padding.Top + 25f, Padding.Right, Padding.Bottom);
}
}
);
var button = new Button() {
Text = "Switch to Tab 1; add a Page 2 there",
};
button.Clicked += async (sender, e) => {
var tabbedPage = this.ParentTabbedPage() as MainTabbedPage;
var partPage = new Page2() { Title = "Added page 2" };
await tabbedPage.SwitchToTab1(partPage, resetToRootFirst: false);
};
Content = new StackLayout {
Children = {
button,
label,
}
};
}
示例11: MultipleChoiceQuestion
public MultipleChoiceQuestion ()
{
Title = "Multiple Choice";
Label q1 = new Label{ Text = "Identify the visual field defect below." };
var answers = new String[]{"Choose an option", "Bitemporal hemianopia", "Binasal hemianopia", "Central scotoma", "Right homonymous hemianopia", "Temporal homonymous hemianopia"};
Picker q1a = new Picker ();
foreach (var a in answers) {
q1a.Items.Add (a);
}
var button = new Button {Text="Submit"};
button.Clicked += (object sender, EventArgs e) => {
if(q1a.SelectedIndex == 1){
DisplayAlert("Correct!", "Well done, that's the right answer", "OK");
}else{
DisplayAlert("Incorrect", String.Format("The correct answer is {0}", answers[1]), "OK");
}
};
Content = new StackLayout {
Children = {
q1,
new Image{
Source = ImageSource.FromUri(new Uri("http://i.imgur.com/q7l03ZG.png"))
},
q1a,
button
}
};
}
示例12: ContentDemo
public ContentDemo()
{
Button button = new Button
{
Text = "Edit Profile",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
button.Clicked += OnButtonClicked;
Image myImage = new Image
{
Aspect = Aspect.Fill,
Source = ImageSource.FromUri( new Uri(@"https://4e72eb44013d543eb0c67f8fbddf2ed30743ec8d.googledrive.com/host/0B70CO9lnNPfceHNFLXh2Wm8yMHc/List-Most-Expensive-Cars-photo-OdYL.jpg"))
};
this.Title = "Content Page";
RelativeLayout relativeLayout = new RelativeLayout ();
relativeLayout.Children.Add (myImage,
Constraint.Constant (0),
Constraint.Constant (0),
Constraint.RelativeToParent ((parent) => { return parent.Width; }),
Constraint.RelativeToParent ((parent) => { return parent.Height; }));
relativeLayout.Children.Add (button,
Constraint.RelativeToParent ((parent) => {return parent.Width/2;} ),
Constraint.RelativeToParent ((parent) => {return parent.Height/2;} ),
Constraint.RelativeToParent ((parent) => { return 75.0; }),
Constraint.RelativeToParent ((parent) => { return 75.0; }));
Content = relativeLayout;
}
示例13: MyPage
public MyPage()
{
Button buttonToUpdate = new Button {Text = "Image Button", Image = "icon.png"};
Button UpdatesList = new Button {Text="Add Item to list"};
buttonToUpdate.SetBinding (Button.ImageProperty, new Binding("ImagePath"));
UpdatesList.Clicked += (sender,e) => {
listToWatch.Add (DateTime.Now.ToString());
};
listToWatch.CollectionChanged+=(sender,e)=>{
if( listToWatch.Count%2==1)
{
ImagePath="noci.png";
}
else
{
ImagePath="icon.png";
}
};
Content = new StackLayout {
Children = {
buttonToUpdate,
UpdatesList
}
};
Content.BindingContext = this;
}
示例14: TableView
public TableView(MatrixMainPageView mainView)
{
InitializeComponent();
_mainView = mainView;
Title = "Таблица";
if (Device.OS == TargetPlatform.iOS)
{
Icon = "tableTabIcon.png";
{
var btn = new Button() { Text = "Фильтры" };
btn.Clicked += (s, e) =>
{
mainView.IsPresented = !mainView.IsPresented;
};
Grid.SetRow(btn,1);
cnvRoot.Children.Add(btn);
}
}
cnvRoot.Padding = Device.OnPlatform(10, 8, 10);
ThemeManager.ThemeName = Themes.Light;
dataGrid.RightSwipeButtons.Add(new SwipeButtonInfo()
{
BackgroundColor = Color.Yellow,
TextColor = Color.Black,
AutoCloseOnTap = true,
Caption = "График"
});
dataGrid.SwipeButtonClick += DataGrid_SwipeButtonClick;
}
示例15: FilterPage
public FilterPage ()
{
this.Icon = "slideout.png";
this.Title = "Filter";
_scope = App.AutoFacContainer.BeginLifetimeScope();
var vm = _scope.Resolve<FilterViewModel> ();
BindingContext = vm;
var layout = new StackLayout ();
layout.Children.Add (new Label() {Text = "Enter a filter"});
layout.Children.Add (new Label() {Text = "Subject"});
var subjectEntry = new Entry();
subjectEntry.SetBinding (Entry.TextProperty, "Subject");
layout.Children.Add (subjectEntry);
var button = new Button () { Text = "Apply Filter" };
button.SetBinding (Button.CommandProperty, "FilterMeasures");
layout.Children.Add (button);
Content = layout;
}