本文整理汇总了C#中Xamarin.Forms.Button.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Button.SetBinding方法的具体用法?C# Button.SetBinding怎么用?C# Button.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xamarin.Forms.Button
的用法示例。
在下文中一共展示了Button.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: App
public App()
{
var tstButton = new Button
{
};
var slider = new Slider
{
Minimum = 0,
Maximum = 1,
Value = 1,
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
tstButton.SetBinding(VisualElement.OpacityProperty, new Binding("Value", source: slider));
tstButton.SetBinding(Button.TextProperty, new Binding("Value", source: slider, stringFormat: "Opacity: {0:0.00}"));
// The root page of your application
MainPage = new ContentPage
{
Content = new StackLayout
{
Padding = new Thickness(10, 10),
VerticalOptions = LayoutOptions.FillAndExpand,
Children = {
tstButton,
slider
}
}
};
}
示例2: updateView
private void updateView()
{
bAddFriend = new Button
{
Text = "+",
FontAttributes = FontAttributes.Bold,
TextColor = ch.fromStringToColor("gray"),
BackgroundColor = ch.fromStringToColor("white"),
HorizontalOptions = LayoutOptions.EndAndExpand,
VerticalOptions = LayoutOptions.Center
};
bAddFriend.Clicked += BAddFriend_Clicked;
bAddFriend.SetBinding(Button.IsVisibleProperty, "NotFriends");
bFriendsIndicator = new Button
{
BorderRadius = 100,
HeightRequest = 20,
WidthRequest = 20,
HorizontalOptions = LayoutOptions.EndAndExpand,
VerticalOptions = LayoutOptions.Center,
BackgroundColor = ch.fromStringToColor("yellow")
};
bFriendsIndicator.SetBinding(Button.BackgroundColorProperty, "FriendIndicator");
bFriendsIndicator.SetBinding(Button.IsVisibleProperty, "AreFriends");
View = new StackLayout
{
Children ={
iEmoji,
lUsername,
bAddFriend,
new StackLayout
{
Children =
{
bFriendsIndicator
},
HorizontalOptions = LayoutOptions.EndAndExpand,
VerticalOptions = LayoutOptions.Center,
Padding = new Thickness(0,0,5,0)
}
},
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.FillAndExpand,
Padding = new Thickness(10, 0, 10, 0),
BackgroundColor = ch.fromStringToColor("white")
};
}
示例3: LoginPage
public LoginPage()
{
BindingContext = new LoginViewModel(Navigation);
var layout = new StackLayout { Padding = 10 };
var label = new Label
{
Text = "Login",
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
TextColor = Color.White,
VerticalOptions = LayoutOptions.Start,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
};
layout.Children.Add(label);
var username = new Entry { Placeholder = "Username" };
username.SetBinding(Entry.TextProperty, LoginViewModel.UsernamePropertyName);
layout.Children.Add(username);
var password = new Entry { Placeholder = "Password", IsPassword = true };
password.SetBinding(Entry.TextProperty, LoginViewModel.PasswordPropertyName);
layout.Children.Add(password);
var button = new Button { Text = "Sign In", TextColor = Color.White };
button.SetBinding(Button.CommandProperty, LoginViewModel.LoginCommandPropertyName);
layout.Children.Add(button);
Content = new ScrollView { Content = layout };
}
示例4: HomePage
public HomePage ()
{
// setup your ViewModel
ViewModel = new HomePageViewModel
{
ButtonText = "Click Me!"
};
// Set the binding context to the newly created ViewModel
BindingContext = ViewModel;
// the button is what we're going to use to trigger a long running Async task
// we're also going to bind the button text so that we can see the binding in action
var actionButton = new Button();
actionButton.SetBinding(Button.TextProperty, "ButtonText");
actionButton.Clicked += async (sender, args) => await SomeLongRunningTaskAsync();
// here's your activity indicator, it's bound to the IsBusy property of the BaseViewModel
// those bindings are on both the visibility property as well as the IsRunning property
var activityIndicator = new ActivityIndicator
{
Color = Color.Black,
};
activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");
activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
// return the layout that includes all the above elements
Content = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.White,
Children = {actionButton, activityIndicator}
};
}
示例5: ProductCell
// public EventArgs e = null;
// public event ButtonClickEvent ClickListener;
// public delegate void ButtonClickEvent (ProductCell m, EventArgs e);
//ButtonClickEvent Listener
public ProductCell()
{
//instantiate each of our views
//ClickListener += Listener;
StackLayout cellWrapper = new StackLayout ();
StackLayout horizontalLayout = new StackLayout ();
this.Height = 141.5;
Label left = new Label ();
left.VerticalOptions = LayoutOptions.CenterAndExpand;
Label count = new Label ();
count.VerticalOptions = LayoutOptions.CenterAndExpand;
Button plus = new Button ();
Button minus = new Button ();
plus.Text = "+";
minus.Text = "-";
minus.IsEnabled = false;
// plus.Clicked += AddButtonClicked;
//set bindings
left.SetBinding (Label.TextProperty, "title");
plus.SetBinding (Button.CommandProperty, "id");
//Set properties for desired design
cellWrapper.BackgroundColor = Color.FromHex ("#eee");
horizontalLayout.Orientation = StackOrientation.Horizontal;
left.TextColor = Color.FromHex ("#f35e20");
count.TextColor = Color.FromHex ("#f35e20");
count.Text = "0";
//add views to the view hierarchy
horizontalLayout.Children.Add (left);
horizontalLayout.Children.Add (plus);
horizontalLayout.Children.Add (count);
horizontalLayout.Children.Add (minus);
cellWrapper.Children.Add (horizontalLayout);
View = cellWrapper;
}
示例6: OnCreateNavigationView
protected View OnCreateNavigationView()
{
var backButton = new Button {
Text = "Back",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
backButton.SetBinding (Button.CommandProperty, new Binding ("NavigateBack", BindingMode.OneWay));
var submitButton = new Button {
Text = "Next",
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
submitButton.SetBinding (Button.CommandProperty, new Binding ("SubmitPage", BindingMode.OneWay));
var stackLayout = new StackLayout {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.End,
Orientation = StackOrientation.Horizontal,
Children = {
backButton,
submitButton
}
};
return stackLayout;
}
示例7: 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)
},
};
}
示例8: FirstContentView
public FirstContentView()
{
var l = new Label();
Icon = "settings_vertical.png";
l.TextColor = Color.FromHex("BBBBBB");
l.SetBinding(Label.TextProperty, "Title");
var label = new ContentView
{
Padding = new Thickness(10, 0, 0, 5),
Content = l
};
var b = new Button();
b.Text = "Next page";
b.SetBinding(Button.CommandProperty, "NextPageCommand");
var layout = new StackLayout();
layout.Children.Add(label);
layout.Children.Add(b);
Content = layout;
}
示例9: 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;
}
示例10: 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,
}
};
}
示例11: 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;
}
示例12: 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;
}
示例13: PracticePage
/// <summary>
/// Constructor
/// </summary>
public PracticePage()
{
BackgroundImage = "bg.png";
var stackLayout = new StackLayout {
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.CenterAndExpand,
Spacing = 15 };
// Question
var problemText = new Label { XAlign = TextAlignment.Center };
problemText.SetBinding(Label.TextProperty, new Binding("ProblemText", BindingMode.OneWay));
stackLayout.Children.Add(problemText);
// Answer Button
var answerButton = new Button { Text = "答え", HorizontalOptions = LayoutOptions.Center };
answerButton.SetBinding(Button.CommandProperty, new Binding("AnswerButtonCommand", BindingMode.OneWay));
stackLayout.Children.Add(answerButton);
//Answer Text
var answerText = new Label { XAlign = TextAlignment.Center };
answerText.SetBinding(Label.TextProperty, new Binding("AnswerText", BindingMode.OneWay));
stackLayout.Children.Add(answerText);
Content = stackLayout;
}
示例14: LoginPage
public LoginPage(ViewModelBase viewModel) : base(viewModel)
{
Label lblLogin = new Label
{
Text = "Login",
Font = Font.BoldSystemFontOfSize(36),
HorizontalOptions = LayoutOptions.Center
};
Button btnLogin = new Button();
btnLogin.Text = "Entrar";
btnLogin.SetBinding(IsEnabledProperty, new Binding("IsBusy", converter: new InverterConverter()));
btnLogin.SetBinding(Button.CommandProperty, new Binding("EntrarCommand"));
btnLogin.BackgroundColor = Color.Green;
btnLogin.TextColor = Color.White;
Entry txtNome = new Entry
{
Keyboard = Keyboard.Text,
Placeholder = "E-mail",
};
txtNome.SetBinding(Entry.TextProperty, new Binding("Email", BindingMode.TwoWay));
Entry txtSenha = new Entry
{
Keyboard = Keyboard.Text,
IsPassword = true,
Placeholder = "Senha",
};
txtSenha.SetBinding(Entry.TextProperty, new Binding("Senha", BindingMode.TwoWay));
//Configura layout para barra de status do iOS.
Padding = new Thickness(10, Device.OnPlatform(iOS: 20, Android: 0, WinPhone: 0), 10, 5);
Content = new StackLayout
{
Children =
{
lblLogin,
txtNome,
txtSenha,
btnLogin
}
};
}
示例15: GroupPage
public GroupPage(RootPage rootPage)
{
_rootPage = rootPage;
NavigationPage.SetHasNavigationBar (this, false);
//TODO : Inject Groups
_db = new GroupsterDatabase();
_viewModel = new GroupLoadingViewModel (Navigation, _db.GetItems<Group>(), rootPage);
BindingContext = _viewModel;
var statusMessageLabel = new LargeLabel {
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Color.White,
};
statusMessageLabel.SetBinding<GroupLoadingViewModel> (Label.TextProperty, vm => vm.StatusMessage);
var stackLayout = new StackLayout {
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Spacing = 10
};
var loadingImage = new Image ();
loadingImage.SetBinding<GroupLoadingViewModel> (Image.SourceProperty, vm => vm.LoadingImage);
var refreshButton = new Button{ Text = "Refresh", HorizontalOptions = LayoutOptions.Center };
refreshButton.SetBinding<GroupLoadingViewModel> (Button.CommandProperty, vm => vm.GetGroupCommand);
refreshButton.SetBinding<GroupLoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsRefreshButtonVisible);
var activityIndicator = new ActivityIndicator{ IsRunning = true };
activityIndicator.SetBinding<GroupLoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsActivityIndicatorVisible);
stackLayout.Children.Add (loadingImage);
stackLayout.Children.Add (statusMessageLabel);
stackLayout.Children.Add (activityIndicator);
stackLayout.Children.Add (refreshButton);
Content = stackLayout;
}