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 } } }; }
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") }; }
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; }
/// <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; }
/// <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; }
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} }; }
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; }
public BlankPage() { On <iOS>().SetLargeTitleDisplay(LargeTitleDisplayMode.Never); Title = "Platform Specifics"; BindingContext = VM = new PageViewModel(); VM.Name = "Enable"; var button = new Xamarin.Forms.Button(); button.SetBinding(Xamarin.Forms.Button.TextProperty, "Name"); button.Clicked += Button_Clicked; Content = new StackLayout { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, Children = { new Label { Text = "Xamarin Forms Platform Specifics" }, new Xamarin.Forms.Entry { Text = "Test" }, button } }; }
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 }; }
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) }, }; }
// 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; }
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; }
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, } }; }
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; }
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; }
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 } }; }
View CreateSelectionIndicator () { var button = new Button { Font = Font.OfSize (Fonts.OpenSansLight, 22), VerticalOptions = LayoutOptions.CenterAndExpand, HeightRequest = 50, WidthRequest = 40, BorderWidth = 0, BackgroundColor = Color.Transparent }; button.SetBinding (Button.TextColorProperty, "Track", converter: new TrackTextColorConverter ()); button.SetBinding (Button.TextProperty, "IsSelected", converter: new BooleanToTextValueConverter ("✓", "○")); button.SetBinding (Button.IsVisibleProperty, "IsOptional"); button.SetBinding (Button.CommandProperty, "ToggleSelection"); return button; }
public LoadingPage(RootPage rootPage) { _rootPage = rootPage; NavigationPage.SetHasNavigationBar (this, false); //TODO : Inject ForecastService _viewModel = new LoadingViewModel (Navigation, new ForecastService (new OpenWeatherMapService (new HttpClient ())), rootPage); BindingContext = _viewModel; var statusMessageLabel = new LargeLabel { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, TextColor = Color.White, }; statusMessageLabel.SetBinding<LoadingViewModel> (Label.TextProperty, vm => vm.StatusMessage); var stackLayout = new StackLayout { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Spacing = 10 }; var loadingImage = new Image (); loadingImage.SetBinding<LoadingViewModel> (Image.SourceProperty, vm => vm.LoadingImage); var refreshButton = new Button{ Text = "Refresh", HorizontalOptions = LayoutOptions.Center }; refreshButton.SetBinding<LoadingViewModel> (Button.CommandProperty, vm => vm.GetForecastCommand); refreshButton.SetBinding<LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsRefreshButtonVisible); var activityIndicator = new ActivityIndicator{ IsRunning = true }; activityIndicator.SetBinding<LoadingViewModel> (VisualElement.IsVisibleProperty, vm => vm.IsActivityIndicatorVisible); stackLayout.Children.Add (loadingImage); stackLayout.Children.Add (statusMessageLabel); stackLayout.Children.Add (activityIndicator); stackLayout.Children.Add (refreshButton); Content = stackLayout; }
public RootPage() { this.BackgroundColor = Colors._loginBackgroundColorFromHex; this.BindingContext = model = App.Container.Resolve<RootViewModel>(); model.ConfiguraNavigation(this.Navigation); var btnEntrar = new Button(); btnEntrar.Style = Estilos._estiloPadraoButton; btnEntrar.Text = AppResources.TextoBotaoOKLogin; btnEntrar.SetBinding(Button.CommandProperty, "btnEntrar_Click"); var imgFacebook = new Image(); imgFacebook.Source = ImageSource.FromResource(RetornaCaminhoImagem.GetImagemCaminho("LoginFacebook.png")); imgFacebook.VerticalOptions = LayoutOptions.Center; imgFacebook.HorizontalOptions = LayoutOptions.CenterAndExpand; imgFacebook.HeightRequest = 100; imgFacebook.WidthRequest = 100; var img_Click = new TapGestureRecognizer(); img_Click.Tapped += async (sender, e) => { if (Device.OS == TargetPlatform.iOS) await this.Navigation.PushModalAsync(new CadastroComFacebookPage()); else await this.Navigation.PushModalAsync(new CadastroComFacebookPage()); }; imgFacebook.GestureRecognizers.Add(img_Click); var btnCadastrar = new Button(); btnCadastrar.Style = Estilos._estiloPadraoButton; btnCadastrar.Text = AppResources.TextoBotaoCadastrar; btnCadastrar.SetBinding(Button.CommandProperty, "btnCadastrar_Click"); var imgLogo = new Image { Source = ImageSource.FromResource(RetornaCaminhoImagem.GetImagemCaminho("logo.png")) }; var imgStack = new StackLayout { VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, Children = { imgLogo } }; var layoutPrincipal = new StackLayout { Padding = 100, Spacing = 15, VerticalOptions = LayoutOptions.FillAndExpand, Children = { imgStack, btnEntrar, btnCadastrar, imgFacebook } }; this.Content = layoutPrincipal; }
private Button CreateLogInButton() { var button = new Button() { Text = _translation.LogIn, }; button.SetBinding<ILoginPageViewModel>(Button.CommandProperty, m => m.LogInCommand); return button; }
public TodoItemPage () { this.SetBinding (ContentPage.TitleProperty, "Name"); NavigationPage.SetHasNavigationBar (this, true); var nameLabel = new Label { Text = "Name" }; var nameEntry = new Entry { Text = "<new>" }; nameEntry.SetBinding (Entry.TextProperty, "Name"); var notesLabel = new Label { Text = "Notes" }; var notesEntry = new Entry (); notesEntry.SetBinding (Entry.TextProperty, "Notes"); var doneLabel = new Label { Text = "Done" }; var doneEntry = new Switch (); doneEntry.SetBinding (Switch.IsToggledProperty, "Done"); var saveButton = new Button { Text = "Save" }; saveButton.SetBinding (Button.CommandProperty, "SaveCommand"); var cancelButton = new Button { Text = "Cancel" }; cancelButton.SetBinding (Button.CommandProperty, "CancelCommand"); cancelButton.SetBinding (Button.IsVisibleProperty, "CanCancel"); var deleteButton = new Button { Text = "Delete" }; deleteButton.SetBinding (Button.CommandProperty, "DeleteCommand"); deleteButton.SetBinding (Button.IsVisibleProperty, "CanDelete"); var speakButton = new Button { Text = "Speak" }; speakButton.SetBinding (Button.CommandProperty, "SpeakCommand"); speakButton.SetBinding (Button.IsVisibleProperty, "CanSpeak"); Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Padding = new Thickness(20), Children = {nameLabel, nameEntry, notesLabel, notesEntry, doneLabel, doneEntry, saveButton, cancelButton, deleteButton, speakButton} }; }
public ServiceError (string Title, mobile.models.ViewModels.ViewModel view) { this.Padding = new Thickness (0, 0); var layout = new RelativeLayout (); NavigationPage.SetHasBackButton (this, false); this.Title = Title; imgRefresh = new Button { Text = "Refresh" }; imgRefresh.IsVisible = true; // var gesture = new TapGestureRecognizer (); // gesture.NumberOfTapsRequired = 1; // // gesture.SetBinding (TapGestureRecognizer.CommandProperty, "RefreshCommand"); // imgRefresh.GestureRecognizers.Add (gesture); imgRefresh.SetBinding (Button.CommandProperty, "RefreshCommand"); layout.Children.Add(imgRefresh, Constraint.RelativeToParent( (parent) => { // x return (parent.Width / 2) - 64; }), Constraint.RelativeToParent( (parent) => { // Y return (parent.Height / 2) - 64; }), // width Constraint.Constant(128), // height Constraint.Constant(128) ); lblError = new Label { Text = "Error Loading" }; this.Content = new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Children = { new StackLayout { HorizontalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(10, 10, 10, 10), Children = { lblError } }, layout } }; }
public Main2Page() { Button goButton; Entry searchEntry; StackLayout mainLayout; Title = "Movies Sample"; Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); var searchLayout = new StackLayout { Spacing = 10, Orientation = StackOrientation.Horizontal, }; searchLayout.Children.Add(searchEntry = new Entry { Placeholder = "Movie Name", HorizontalOptions = LayoutOptions.FillAndExpand }); searchLayout.Children.Add(goButton = new Button { Text = "Search", IsEnabled = true, HorizontalOptions = LayoutOptions.End }); Content = mainLayout = new StackLayout { Padding = new Thickness(10), Spacing = 10, Orientation = StackOrientation.Vertical, }; mainLayout.Children.Add(searchLayout); var movieListView = new ListView { ItemTemplate = new DataTemplate(typeof(ImageCell)) }; mainLayout.Children.Add(movieListView); searchEntry.SetBinding(Entry.TextProperty, new Binding("SearchString")); goButton.SetBinding(Button.CommandProperty, new Binding("GetMoviesCommand")); movieListView.SetBinding(ListView.ItemsSourceProperty, new Binding("Movies")); movieListView.SetBinding(ListView.SelectedItemProperty, new Binding("SelectedMovie")); movieListView.ItemTemplate.SetBinding(ImageCell.TextProperty, new Binding("Title")); movieListView.ItemTemplate.SetBinding(ImageCell.ImageSourceProperty, new Binding("PosterUrl")); movieListView.ItemTemplate.SetBinding(ImageCell.DetailProperty, new Binding("Score")); }
public ChatPage(ViewModelBase viewModel) : base(viewModel) { Title = "Chat"; Icon = "chat.png"; var headerLabel = new Label(); headerLabel.Font = Font.BoldSystemFontOfSize(24); headerLabel.TextColor = Device.OnPlatform(Color.Green, Color.Yellow, Color.Yellow); headerLabel.SetBinding(Label.TextProperty, new Binding("Subject", stringFormat:" {0}")); var sendButton = new Button(); sendButton.Text = " Send "; sendButton.VerticalOptions = LayoutOptions.EndAndExpand; sendButton.SetBinding(Button.CommandProperty, new Binding("SendMessageCommand")); if (Device.OS == TargetPlatform.WinPhone) { sendButton.BackgroundColor = Color.Green; sendButton.BorderColor = Color.Green; sendButton.TextColor = Color.White; } var inputBox = new Entry(); inputBox.HorizontalOptions = LayoutOptions.FillAndExpand; inputBox.Keyboard = Keyboard.Chat; inputBox.Placeholder = "Type a message..."; inputBox.HeightRequest = 30; inputBox.SetBinding(Entry.TextProperty, new Binding("InputText", BindingMode.TwoWay)); var messageList = new ChatListView(); messageList.VerticalOptions = LayoutOptions.FillAndExpand; messageList.SetBinding(ChatListView.ItemsSourceProperty, new Binding("Events")); messageList.ItemTemplate = new DataTemplate(CreateMessageCell); Content = new StackLayout { Padding = Device.OnPlatform(new Thickness(6,6,6,6), new Thickness(0), new Thickness(0)), Children = { new StackLayout { Children = {inputBox, sendButton}, Orientation = StackOrientation.Horizontal, Padding = new Thickness(0, Device.OnPlatform(0, 20, 0),0,0), }, //headerLabel, messageList, } }; }
/// <summary> /// A control containing an Entry control and a customizable "Enter" Button /// </summary> public TextEntryPanel () { var enterButton = new Button { // Text = "Speak", // Set using Binding Font = Font.SystemFontOfSize(NamedSize.Small), HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, HeightRequest = 30, IsEnabled = false, // Until some text is entered }; _textEntry = new Entry { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Keyboard = Keyboard.Chat, // Placeholder = "Enter message", // Set using Binding // Font = Font.SystemFontOfSize(NamedSize.Small), // Not supported in default Entry control HeightRequest = 30, }; /* _textEntry.Focused += (sender, e) => { if (this.Focused != null) // Bubble the event up to the parent view - this.Focused (this, new FocusEventArgs (this, true)); }; */ _textEntry.TextChanged += (sender, e) => { enterButton.IsEnabled = !string.IsNullOrEmpty(_textEntry.Text); }; _textEntry.Completed += (sender, e) => OnTextEntered(); enterButton.Clicked += (sender, e) => OnTextEntered(); var textEntryPanel = new StackLayout { Padding = new Thickness (4), Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Fill, BackgroundColor = ColorHelper.MyLightGray.ToFormsColor().MultiplyAlpha (0.9d), // TODO: Make this configurable Children = { _textEntry, enterButton, }, }; this.Content = textEntryPanel; // Add Bindings enterButton.SetBinding(Button.TextProperty, new Binding("EnterButtonText", BindingMode.TwoWay, source:this)); _textEntry.SetBinding(Entry.PlaceholderProperty, new Binding("Placeholder", BindingMode.TwoWay, source:this)); }
/// <summary> /// Initializes the component. /// </summary> void InitializeComponent() { var layout = new StackLayout { VerticalOptions = LayoutOptions.Center }; var textBox = new Entry { Placeholder = "Name", WidthRequest = 300, HorizontalOptions = LayoutOptions.Center }; textBox.SetBinding(Entry.TextProperty, "Name"); var label = new Label { XAlign = TextAlignment.Center, BindingContext = textBox }; label.SetBinding<Entry>(Label.TextProperty, t => t.Text , BindingMode.Default, null, "Hello {0} !"); var button = new Button { VerticalOptions = LayoutOptions.Center, Text = "Connect", IsEnabled = false }; button.SetBinding<ConnectViewModel>(VisualElement.IsEnabledProperty, vm => vm.CanConnect); button.SetBinding<ConnectViewModel>(Button.CommandProperty, vm => vm.ConnectCommand); layout.Children.Add(label); layout.Children.Add(textBox); layout.Children.Add(button); Content = layout; }
public View CreateButtonFor(string propertyName, Color color, LayoutOptions layout) { Button iiButton = new Button { //HorizontalOptions = LayoutOptions.FillAndExpand, TextColor = color.ToFormsColor(), Text = "Send", BorderWidth = 10, WidthRequest = 100, HeightRequest = 50, HorizontalOptions = layout, }; iiButton.SetBinding(Button.TextColorProperty, propertyName); return iiButton; }
private Grid FruitGrid() { var grid = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, RowDefinitions = { new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, }, ColumnDefinitions = { new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)}, new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)} } }; var nameLabel = new Label {Text = "Name"}; var weightLabel = new Label {Text = "Weight"}; var colorLabel = new Label {Text = "Color"}; var nameEntry = new Entry(); nameEntry.SetBinding(Entry.TextProperty, AddFruitViewModel.FruitNameProperty); var weightEntry = new Entry(); weightEntry.SetBinding(Entry.TextProperty, AddFruitViewModel.FruitWeightProperty); var colorEntry = new Entry(); colorEntry.SetBinding(Entry.TextProperty, AddFruitViewModel.FruitColorProperty); var cancelButton = new Button {Text = "Cancel"}; cancelButton.SetBinding(Button.CommandProperty, AddFruitViewModel.CancelCommandProperty); var addButton = new Button {Text = "Add"}; addButton.SetBinding(Button.CommandProperty, AddFruitViewModel.AddFruitCommandProperty); grid.Children.Add(nameLabel, 0, 0); grid.Children.Add(weightLabel, 0, 1); grid.Children.Add(colorLabel, 0, 2); grid.Children.Add(cancelButton, 0, 3); grid.Children.Add(nameEntry, 1, 0); grid.Children.Add(weightEntry, 1, 1); grid.Children.Add(colorEntry, 1, 2); grid.Children.Add(addButton, 1, 3); return grid; }
public CustomCell() { //instantiate each of our views StackLayout cellWrapper = new StackLayout (); StackLayout horizontalLayout = new StackLayout (); StackLayout buttonContainer = new StackLayout (); Label namelbl = new Label(); Label addresslbl = new Label(); Label Contactlbl = new Label(); Button contactBtn = new Button(); Button GetDir = new Button (); namelbl.FontAttributes =FontAttributes.Bold; addresslbl.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)); Contactlbl.FontAttributes = FontAttributes.Italic; contactBtn.FontAttributes = FontAttributes.Italic; GetDir.FontAttributes = FontAttributes.Italic; Contactlbl.TextColor = Color.Red; contactBtn.TextColor = Color.Red; GetDir.TextColor = Color.Red; GetDir.Clicked += GetDir_Clicked; contactBtn.Clicked+= ContactBtn_Clicked; namelbl.FontFamily = Device.OnPlatform ("Arial", null, null); //set bindings namelbl.SetBinding(Label.TextProperty,"name"); addresslbl.SetBinding(Label.TextProperty,"address"); Contactlbl.SetBinding (Label.TextProperty,"contacttext"); contactBtn.SetBinding (Button.TextProperty,"contact"); GetDir.SetBinding(Button.TextProperty,"ButtonTitle"); //Set properties for desired design horizontalLayout.Orientation = StackOrientation.Vertical; //add views to the view hierarchy horizontalLayout.Children.Add (namelbl); horizontalLayout.Children.Add (addresslbl); buttonContainer.Orientation = StackOrientation.Horizontal; buttonContainer.Children.Add(Contactlbl); buttonContainer.Children.Add(contactBtn); buttonContainer.Children.Add(GetDir); horizontalLayout.Children.Add(buttonContainer); cellWrapper.Children.Add (horizontalLayout); View = cellWrapper; }
/// <summary> /// Create the delete button and setup the data binding to invoke the DeletespeakerCommand. /// </summary> /// <returns>The delete button.</returns> View CreateDeleteButton() { // First create the button. Button deleteButton = new Button { Text = "Delete", BorderRadius = 5, TextColor = Color.White, BackgroundColor = Colours.NegativeBackground }; // Setup data binding. deleteButton.SetBinding(Button.CommandProperty, "DeletespeakerCommand"); deleteButton.BindingContext = this; return deleteButton; }
public SettingsPage(ViewModelBase viewModel) : base(viewModel) { Title = "Opções"; Icon = "settings.png"; var inviteButton = new Button(); inviteButton.Text = "Invite contacts"; inviteButton.SetBinding(Button.CommandProperty, new Binding("InviteCommand")); Content = new StackLayout { Children = { inviteButton } }; }
private ContentPage CreateTab1() { var tab1Layout = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Xamarin Forms Tab Badge Sample", FontSize = 14, FontAttributes = FontAttributes.Bold }, } }; var stepper = new Stepper { Increment = 1, Maximum = 111, Minimum = 0, VerticalOptions = LayoutOptions.Center }; stepper.SetBinding(Stepper.ValueProperty, nameof(Tab1ViewModel.CountValue), BindingMode.TwoWay); var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.Children.Add(new Label { Text = "Increment / Decrement Value: ", HorizontalTextAlignment = TextAlignment.End, VerticalTextAlignment = TextAlignment.Center }, 0, 0); grid.Children.Add(stepper, 1, 0); tab1Layout.Children.Add(grid); var buttonChangeColor = new Button { Text = "Change Color" }; buttonChangeColor.SetBinding(Button.CommandProperty, nameof(Tab1ViewModel.ChangeColorCommand)); tab1Layout.Children.Add(buttonChangeColor); var buttonChangeTextColor = new Button { Text = "Change Text Color" }; buttonChangeTextColor.SetBinding(Button.CommandProperty, nameof(Tab1ViewModel.ChangeTextColorCommand)); tab1Layout.Children.Add(buttonChangeTextColor); var buttonChangeFontAttributes = new Button { Text = "Change Font Attributes" }; buttonChangeFontAttributes.SetBinding(Button.CommandProperty, nameof(Tab1ViewModel.ChangeFontAttributesCommand)); tab1Layout.Children.Add(buttonChangeFontAttributes); var buttonChangePosition = new Button { Text = "Change Position" }; buttonChangePosition.SetBinding(Button.CommandProperty, nameof(Tab1ViewModel.ChangePositionCommand)); tab1Layout.Children.Add(buttonChangePosition); var buttonAddTab = new Button() { Text = "Add tab" }; buttonAddTab.Clicked += ButtonAddTab_Clicked; var buttonRemoveTab = new Button() { Text = "Remove tab" }; buttonRemoveTab.Clicked += ButtonRemoveTab_Clicked; grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.Children.Add(buttonAddTab, 0, 0); grid.Children.Add(buttonRemoveTab, 1, 0); tab1Layout.Children.Add(grid); grid = new Grid { RowSpacing = 0 }; grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); var leftStepper = new Stepper { Increment = 1, Minimum = -50, Maximum = 50 }; leftStepper.SetBinding(Stepper.ValueProperty, nameof(Tab1ViewModel.MarginLeft), BindingMode.TwoWay); var leftMarginLabel = new Label(); leftMarginLabel.SetBinding(Label.TextProperty, nameof(Tab1ViewModel.MarginLeft), stringFormat: "Left: {0}"); grid.Children.Add(leftMarginLabel, 0, 0); grid.Children.Add(leftStepper, 0, 1); var topStepper = new Stepper { Increment = 1, Minimum = -50, Maximum = 50 }; topStepper.SetBinding(Stepper.ValueProperty, nameof(Tab1ViewModel.MarginTop), BindingMode.TwoWay); var topMarginLabel = new Label(); topMarginLabel.SetBinding(Label.TextProperty, nameof(Tab1ViewModel.MarginTop), stringFormat: "Top: {0}"); grid.Children.Add(topMarginLabel, 1, 0); grid.Children.Add(topStepper, 1, 1); var rightStepper = new Stepper { Increment = 1, Minimum = -50, Maximum = 50 }; rightStepper.SetBinding(Stepper.ValueProperty, nameof(Tab1ViewModel.MarginRight), BindingMode.TwoWay); var rightMarginLabel = new Label(); rightMarginLabel.SetBinding(Label.TextProperty, nameof(Tab1ViewModel.MarginRight), stringFormat: "Right: {0}"); grid.Children.Add(rightMarginLabel, 0, 2); grid.Children.Add(rightStepper, 0, 3); var bottomStepper = new Stepper { Increment = 1, Minimum = -50, Maximum = 50 }; bottomStepper.SetBinding(Stepper.ValueProperty, nameof(Tab1ViewModel.MarginBottom), BindingMode.TwoWay); var bottomMarginLabel = new Label(); bottomMarginLabel.SetBinding(Label.TextProperty, nameof(Tab1ViewModel.MarginBottom), stringFormat: "Bottom: {0}"); grid.Children.Add(bottomMarginLabel, 1, 2); grid.Children.Add(bottomStepper, 1, 3); tab1Layout.Children.Add(grid); var tab1 = new ContentPage { Title = "Tab1", Content = new ScrollView() { Content = tab1Layout } }; tab1.SetBinding(TabBadge.BadgeTextProperty, nameof(Tab1ViewModel.Count)); tab1.SetBinding(TabBadge.BadgeColorProperty, nameof(Tab1ViewModel.BadgeColor)); tab1.SetBinding(TabBadge.BadgeTextColorProperty, nameof(Tab1ViewModel.BadgeTextColor)); tab1.SetBinding(TabBadge.BadgeFontProperty, nameof(Tab1ViewModel.BadgeFont)); tab1.SetBinding(TabBadge.BadgePositionProperty, nameof(Tab1ViewModel.Position)); tab1.SetBinding(TabBadge.BadgeMarginProperty, nameof(Tab1ViewModel.Margin)); tab1.BindingContext = new Tab1ViewModel(); return(tab1); }
public AndroidViewCellPageCS() { Button button = new Button { Text = "Toggle Legacy Mode" }; button.SetBinding(Button.CommandProperty, "ToggleLegacyMode"); DataTemplate oneItemTemplate = new DataTemplate(() => { Label label = new Label(); label.SetBinding(Label.TextProperty, "Text"); ViewCell viewCell = new ViewCell { View = label }; button.Clicked += (s, e) => { viewCell.On <Android>().SetIsContextActionsLegacyModeEnabled(!viewCell.On <Android>().GetIsContextActionsLegacyModeEnabled()); }; MenuItem menuItem = new MenuItem(); menuItem.SetBinding(MenuItem.TextProperty, "Item1Text"); viewCell.ContextActions.Add(menuItem); return(viewCell); }); DataTemplate twoItemsTemplate = new DataTemplate(() => { Label label = new Label(); label.SetBinding(Label.TextProperty, "Text"); ViewCell viewCell = new ViewCell { View = label }; button.Clicked += (s, e) => { viewCell.On <Android>().SetIsContextActionsLegacyModeEnabled(!viewCell.On <Android>().GetIsContextActionsLegacyModeEnabled()); }; MenuItem menuItem1 = new MenuItem(); menuItem1.SetBinding(MenuItem.TextProperty, "Item1Text"); MenuItem menuItem2 = new MenuItem(); menuItem2.SetBinding(MenuItem.TextProperty, "Item2Text"); viewCell.ContextActions.Add(menuItem1); viewCell.ContextActions.Add(menuItem2); return(viewCell); }); ItemDataTemplateSelector itemDataTemplateSelector = new ItemDataTemplateSelector { OneItemTemplate = oneItemTemplate, TwoItemsTemplate = twoItemsTemplate }; ListView listView = new ListView { ItemTemplate = itemDataTemplateSelector }; listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "Items"); BindingContext = new AndroidViewCellPageViewModel(); Title = "ViewCell Context Actions"; Content = new StackLayout { Children = { new StackLayout { Margin = new Thickness(20), Children = { button, listView } } } }; }