/// <summary> /// Initialize an image button layout /// Add LongTapGesture recognizer for displaying pressed color and invoke click event. /// </summary> public ImageButton() : base() { var image = new Image() { Source = Source, }; image.BindingContext = this; image.SetBinding(Image.SourceProperty, new Binding("Source")); image.SetBinding(Image.MinimumWidthRequestProperty, new Binding("MinWidth")); image.SetBinding(Image.MinimumHeightRequestProperty, new Binding("MinHeight")); var gestureRecognizer = new LongTapGestureRecognizer(); //When tap event is invoked. add pressed color to image. gestureRecognizer.TapStarted += (s, e) => { //change forground blend color of image ImageAttributes.SetBlendColor(image, Color.FromRgb(213, 228, 240)); }; //If tap is released. set default color to image. gestureRecognizer.TapCanceled += (s, e) => { //revert forground blend color of image ImageAttributes.SetBlendColor(image, Color.Default); SendClicked(); }; //If tap is completed. set default color to image. gestureRecognizer.TapCompleted += (s, e) => { //revert forground blend color of image ImageAttributes.SetBlendColor(image, Color.Default); SendClicked(); }; GestureRecognizers.Add(gestureRecognizer); Children.Add( image, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(parent.Width); }), Constraint.RelativeToParent((parent) => { return(parent.Height); })); }
View CreateContent(ImageCell cell) { XForm.Label text = new XForm.Label { HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Start, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, FontAttributes = FontAttributes.Bold, }; XForm.Label detailLabel = new XForm.Label { HorizontalTextAlignment = TextAlignment.Start, VerticalTextAlignment = TextAlignment.Start, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, }; detailLabel.FontSize = Device.GetNamedSize(NamedSize.Micro, detailLabel); text.SetBinding(XForm.Label.TextProperty, new Binding("Text", source: cell)); text.SetBinding(XForm.Label.TextColorProperty, new Binding("TextColor", source: cell)); detailLabel.SetBinding(XForm.Label.TextProperty, new Binding("Detail", source: cell)); detailLabel.SetBinding(XForm.Label.TextColorProperty, new Binding("DetailColor", source: cell)); XForm.Image image = new XForm.Image { HeightRequest = Element.ItemHeight, WidthRequest = Element.ItemWidth, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, Aspect = Aspect.Fill }; image.SetBinding(XForm.Image.SourceProperty, new Binding("ImageSource", source: cell)); var view = new AbsoluteLayout(); view.Children.Add(image, new XForm.Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); view.Children.Add(new StackLayout { VerticalOptions = LayoutOptions.EndAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { new StackLayout { VerticalOptions = LayoutOptions.EndAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Padding = 15, Spacing = 0, BackgroundColor = XForm.Color.FromHex("#2b7c87"), Children = { text, detailLabel } } } }, new XForm.Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All); cell.SetBinding(GridView.BindingContextProperty, new Binding("BindingContext", source: view)); return(view); }
public TestClassCell() { _label.ActionTagTapped += (sender, e) => Forms9Patch.Toast.Create(null, e.Href); _stackLayout.Children.Add(_statusIcon); _stackLayout.Children.Add(_label); _frame.Content = _stackLayout; View = _frame; _label.SetBinding(Forms9Patch.Label.HtmlTextProperty, "Content"); _label.SetBinding(Forms9Patch.Label.TextColorProperty, "TextColor"); _statusIcon.SetBinding(Xamarin.Forms.Image.SourceProperty, "StatusIcon"); _frame.SetBinding(Forms9Patch.Frame.BackgroundColorProperty, "BackgroundColor"); }
/// <summary> /// To initialize UI Components of an application information page /// </summary> private void InitializeComponent() { Title = "ApplicationInfo"; /// The mainLayout consists of several parts to display application information. var mainLayout = new RelativeLayout { }; /// To display an image as the background var background = new Background { Image = new FileImageSource { File = "background_app.png" }, Option = BackgroundOptions.Stretch, }; mainLayout.Children.Add( background, Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(0); }), Constraint.RelativeToParent((parent) => { return(parent.Width); }), Constraint.RelativeToParent((parent) => { return(parent.Height); })); /// To display an application icon path var icon = new Image { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; mainLayout.Children.Add( icon, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0556); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0537); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.1319); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0774); })); /// To display an application name var applicationName = new Label { }; applicationName.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( applicationName, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.2472); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0961); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.7389); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0293); })); /// To display an application ID var applicationID = new Label { }; applicationID.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( applicationID, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0375); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.3014); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4486); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0319); })); /// To display an application version var applicationVersion = new Label { }; applicationVersion.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( applicationVersion, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.5416); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.3014); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4486); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0319); })); /// To display the device memory status var memoryLED = new Image { Source = "led.png" }; mainLayout.Children.Add( memoryLED, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0375); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.4661); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0236); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0152); })); /// To dispay the device battery status var batteryLED = new Image { Source = "led.png" }; mainLayout.Children.Add( batteryLED, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.5416); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.4661); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0236); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0152); })); /// To display the language setting on the device var language = new Label { }; language.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( language, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0375); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.7032); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4486); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0319); })); /// To display the region format setting on the device var regionFormat = new Label { }; regionFormat.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( regionFormat, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.5416); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.7032); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4486); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0319); })); /// To display the orientation of the device var deviceOrienation = new Label { }; deviceOrienation.Style = ApplicationInformationStyle.ContentStyle; mainLayout.Children.Add( deviceOrienation, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.0375); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.9109); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4661); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.0321); })); /// To display the orientation degree of the device var rotationDegree = new Label { }; rotationDegree.Style = ApplicationInformationStyle.LargerContentStyle; mainLayout.Children.Add( rotationDegree, Constraint.RelativeToParent((parent) => { return(parent.Width * 0.5416); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.8254); }), Constraint.RelativeToParent((parent) => { return(parent.Width * 0.4486); }), Constraint.RelativeToParent((parent) => { return(parent.Height * 0.1276); })); BindingContextChanged += (s, e) => { if (BindingContext == null) { return; } icon.Source = ((ApplicationInformationViewModel)BindingContext).IconPath; applicationName.Text = ((ApplicationInformationViewModel)BindingContext).Name; applicationID.Text = ((ApplicationInformationViewModel)BindingContext).ID; applicationVersion.Text = ((ApplicationInformationViewModel)BindingContext).Version; memoryLED.BindingContext = BindingContext; batteryLED.BindingContext = BindingContext; language.BindingContext = BindingContext; regionFormat.BindingContext = BindingContext; deviceOrienation.BindingContext = BindingContext; rotationDegree.BindingContext = BindingContext; language.SetBinding(Label.TextProperty, "Language"); regionFormat.SetBinding(Label.TextProperty, "RegionFormat"); deviceOrienation.SetBinding(Label.TextProperty, "DeviceOrientation"); rotationDegree.SetBinding(Label.TextProperty, "RotationDegree"); memoryLED.SetBinding(ImageAttributes.BlendColorProperty, "LowMemoryLEDColor"); batteryLED.SetBinding(ImageAttributes.BlendColorProperty, "LowBatteryLEDColor"); }; /// Set mainLayou as Content of the page Content = mainLayout; }
public EventbriteViewPage() { Title = "Eventbrite"; BackgroundColor = Color.White; var foursquareViewModel = new EventbriteViewModel(); BindingContext = foursquareViewModel; var pageTitleLabel = new Label { Text = "Eventbrite", TextColor = Color.Gray, FontSize = 24 }; var dataTemplate = new DataTemplate(() => { var eventNameLabel = new Label { TextColor = Color.FromHex("#FF8832"), FontSize = 20 }; eventNameLabel.SetBinding(Label.TextProperty, new Binding("Name.Text")); var eventStartLabel = new Label { TextColor = Color.Gray, FontSize = 14 }; eventStartLabel.SetBinding(Label.TextProperty, new Binding("Start.Utc")); var eventEndLabel = new Label { TextColor = Color.Gray, FontSize = 14 }; eventEndLabel.SetBinding(Label.TextProperty, new Binding("End.Utc")); var eventDescriptionLabel = new Label { FontSize = 14, TextColor = Color.Black, HeightRequest = 100, }; eventDescriptionLabel.SetBinding(Label.TextProperty, new Binding("Description.Text")); var eventAddressLabel = new Label { FontSize = 14, TextColor = Color.Gray, }; eventAddressLabel.SetBinding(Label.TextProperty, new Binding("Venue.Address.Localized_Address_Display")); var logoImage = new Image { WidthRequest = 120, HeightRequest = 65, VerticalOptions = LayoutOptions.Start, }; logoImage.SetBinding(Image.SourceProperty, new Binding("Logo.Url")); return(new ViewCell { View = new StackLayout { Orientation = StackOrientation.Vertical, Padding = new Thickness(0, 5, 0, 10), Children = { new StackLayout { Orientation = StackOrientation.Horizontal, Children = { logoImage, eventNameLabel, } }, eventAddressLabel, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { eventStartLabel, eventEndLabel } }, eventDescriptionLabel, } } }); }); var listView = new ListView { HasUnevenRows = true }; listView.SetBinding(ListView.ItemsSourceProperty, "EventbriteEvents.Events"); listView.ItemTemplate = dataTemplate; Content = new StackLayout { Padding = new Thickness(5, 10), Children = { pageTitleLabel, listView } }; }