protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { winButton = Control; formsElement = (CustomImageButton)this.Element; if( formsElement.TextOrientation == TextOrientation.Left ) { winButton.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; } else if (formsElement.TextOrientation == TextOrientation.Middle) { winButton.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; } else { winButton.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right; } formsElement.BorderColor = Xamarin.Forms.Color.Transparent; formsElement.BorderWidth = 0; if (formsElement.ImageName != null ) winButton.Background = new ImageBrush { Stretch = System.Windows.Media.Stretch.Fill, ImageSource = new BitmapImage(new Uri(formsElement.ImageName, UriKind.Relative)) }; } }
protected override void OnElementChanged(ElementChangedEventArgs<Label> e) { base.OnElementChanged(e); var view = (ExtendedLabel)Element; UpdateUi(view, Control); }
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged(e); page = e.NewElement as ConnectPage; var activity = this.Context as Activity; page.PlatformParameters = new PlatformParameters(activity); }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Frame> e) { base.OnElementChanged(e); if (Element == null) return; player = new MediaElement(); player.AutoPlay = true; player.MediaOpened += (sender, args) => { timer.Start(); }; this.Control.Child = player; timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 1) }; timer.Tick += timer_Tick; if (string.IsNullOrWhiteSpace(Player.Url)) return; InitPlayer(); }
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e) { base.OnElementChanged(e); CustomTimePicker timePicker = (CustomTimePicker)Element; if (timePicker != null) { SetBorderStyle(timePicker); SetTextColor(timePicker); Control.AdjustsFontSizeToFitWidth = true; } if (e.OldElement == null) { //Wire events } if (e.NewElement == null) { //Unwire events } }
/// <summary> /// Handles the initial drawing of the button. /// </summary> /// <param name="e">Information on the <see cref="ImageButton"/>.</param> protected async override void OnElementChanged(ElementChangedEventArgs<Button> e) { base.OnElementChanged(e); var imageButton = ImageButton; var targetButton = Control; if (imageButton != null && targetButton != null && imageButton.Source != null) { await SetImageAsync(imageButton.Source, this.GetWidth(imageButton.ImageWidthRequest), this.GetHeight(imageButton.ImageHeightRequest), targetButton); switch (imageButton.Orientation) { case ImageOrientation.ImageToLeft: AlignToLeft(targetButton); break; case ImageOrientation.ImageToRight: AlignToRight(imageButton.ImageWidthRequest, targetButton); break; case ImageOrientation.ImageOnTop: AlignToTop(imageButton.ImageHeightRequest, imageButton.ImageWidthRequest, targetButton); break; case ImageOrientation.ImageOnBottom: AlignToBottom(imageButton.ImageHeightRequest, imageButton.ImageWidthRequest, targetButton); break; } } }
protected async override void OnElementChanged (ElementChangedEventArgs<Button> e) { base.OnElementChanged (e); if (byPassButton == null) { byPassButton = new UIButton (UIButtonType.Custom); byPassButton.Frame = this.Frame; SetNativeControl (byPassButton); base.Control.TouchUpInside += byPassButton_TouchUpInside; SetField (this, "buttonTextColorDefaultNormal", base.Control.TitleColor (UIControlState.Normal)); SetField (this, "buttonTextColorDefaultHighlighted", base.Control.TitleColor (UIControlState.Highlighted)); SetField (this, "buttonTextColorDefaultDisabled", base.Control.TitleColor (UIControlState.Disabled)); InvokeMethod (this, "UpdateText", null); InvokeMethod (this, "UpdateFont", null); InvokeMethod (this, "UpdateBorder", null); InvokeMethod (this, "UpdateImage", null); InvokeMethod (this, "UpdateTextColor", null); } if (e.NewElement != null) { Control.ShowsTouchWhenHighlighted = false; Control.AdjustsImageWhenHighlighted = false; await SetNormalImageResource (); await SetDisableImageResource (); await SetPressImageResource (); } }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Switch> e) { base.OnElementChanged(e); var view = (SwitchExtended)Element; if (Control != null) { Control.TextOn = view.TextOn; Control.TextOff = view.TextOff; } /*if (e.OldElement != null) { this.Element.Toggled -= ElementToggled; return; } if (this.Element == null) { return; } var switchControl = new Android.Widget.Switch(Forms.Context) { TextOn = this.Element.TextOn, TextOff = this.Element.TextOff }; switchControl.CheckedChange += ControlValueChanged; this.Element.Toggled += ElementToggled; this.SetNativeControl(switchControl);*/ }
protected override void OnElementChanged(ElementChangedEventArgs<Label> e) { base.OnElementChanged(e); // The first time OnElementPropertyChanged isn't called for Text, so call it by ourselfs OnElementPropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Text")); }
protected override void OnElementChanged (ElementChangedEventArgs<View> e) { base.OnElementChanged (e); //Get the video //bubble up to the AVPlayerLayer var url = new NSUrl ("http://www.androidbegin.com/tutorial/AndroidCommercial.3gp"); _asset = AVAsset.FromUrl (url); _playerItem = new AVPlayerItem (_asset); _player = new AVPlayer (_playerItem); _playerLayer = AVPlayerLayer.FromPlayer (_player); //Create the play button playButton = new UIButton (); playButton.SetTitle ("Play Video", UIControlState.Normal); playButton.BackgroundColor = UIColor.Gray; //Set the trigger on the play button to play the video playButton.TouchUpInside += (object sender, EventArgs arg) => { _player.Play(); }; }
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged(e); page = new MyThirdNativePage(); this.Children.Add(page); }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { var nativePhoneTextBox = (PhoneTextBox)Control.Children[0]; //var nativePasswordBox = (PhoneTextBox)Control.Children[1]; nativePhoneTextBox.Background = new SolidColorBrush(Colors.Yellow); nativePhoneTextBox.BorderBrush = new SolidColorBrush(Colors.Transparent); nativePhoneTextBox.Height = 100; nativePhoneTextBox.Margin = new System.Windows.Thickness(2,-10,2,5); nativePhoneTextBox.BorderThickness = new Thickness(0); nativePhoneTextBox.GotFocus += GotFocusaAction; nativePhoneTextBox.LostFocus += LostFocusAction; var border = new Border(); border.CornerRadius = new CornerRadius(25); border.BorderThickness = new System.Windows.Thickness(1); border.BorderBrush = new SolidColorBrush(Colors.Brown); border.Background = new SolidColorBrush(Colors.Yellow); border.Margin = new System.Windows.Thickness(10); var parent = nativePhoneTextBox.Parent as System.Windows.Controls.Grid; if (parent != null) { parent.Children.Remove(nativePhoneTextBox); parent.Children.Add(border); border.Child = nativePhoneTextBox; } } }
/// <summary> /// Raises the element changed event. /// </summary> /// <param name="e">E.</param> protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e) { base.OnElementChanged(e); if (e.NewElement != null) UpdateFont(); }
protected override void OnElementChanged(ElementChangedEventArgs<View> e) { base.OnElementChanged(e); var adMobElement = Element as AdmobBannerView; if (null != adMobElement) { adView = new GADBannerView(GADAdSizeCons.Banner) { AdUnitID = adMobElement.AdUnitID, RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController }; adView.AdReceived += (sender, args) => { if (!viewOnScreen) AddSubview(adView); viewOnScreen = true; }; adView.LoadRequest(GADRequest.Request); SetNativeControl(adView); } }
protected override void OnElementChanged(ElementChangedEventArgs<View> e) { base.OnElementChanged(e); if (e.OldElement != null) { var nativeMap = Control as MKMapView; nativeMap.GetViewForAnnotation = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView; } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; var nativeMap = Control as MKMapView; customPins = formsMap.CustomPins; nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView; } }
protected override void OnElementChanged(ElementChangedEventArgs<Image> e) { base.OnElementChanged(e); if (Element == null) return; CreateCircle(); }
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) { base.OnElementChanged(e); base.OnElementChanged(e); UITextView textView = (UITextView)Control; //Color textView.BackgroundColor = UIColor.White; textView.TextColor = UIColor.Gray; //font //textField.Font = UIFont.FromName("Ubuntu-light", 13); replacingControl = new UITextView(Control.Bounds); var adelegate = new CustomTextViewDelegate(); var element = this.Element as PurposeColor.CustomControls.CustomEditor; adelegate.Placeholder = element.Placeholder; adelegate.formsEditor = element; replacingControl.Delegate = adelegate; replacingControl.TextColor = UIColor.LightGray; replacingControl.Text = adelegate.Placeholder; this.SetNativeControl(replacingControl); }//OnElementChanged()
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged(e); // this is a ViewGroup - so should be able to load an AXML file and FindView<> var activity = this.Context as Activity; var auth = new OAuth2Authenticator ( clientId: App.Instance.OAuthSettings.ClientId, // your OAuth2 client id scope: App.Instance.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API. authorizeUrl: new Uri (App.Instance.OAuthSettings.AuthorizeUrl), // the auth URL for the service redirectUrl: new Uri (App.Instance.OAuthSettings.RedirectUrl)); // the redirect URL for the service auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { App.Instance.SuccessfulLoginAction.Invoke(); // Use eventArgs.Account to do wonderful things App.Instance.SaveToken(eventArgs.Account.Properties["access_token"]); } else { // The user cancelled } }; activity.StartActivity (auth.GetUI(activity)); }
protected override void OnElementChanged(ElementChangedEventArgs<Label> e) { base.OnElementChanged(e); if (Control != null) { var view = (LabelExtended)Element; if (view.IsWrapped) { Control.TextWrapping = System.Windows.TextWrapping.Wrap; Control.TextTrimming = System.Windows.TextTrimming.WordEllipsis; Control.Loaded += (s, args) => { var parent = Control.Parent as LabelExtendedRenderer; if (parent != null) { var grid = new System.Windows.Controls.Grid(); parent.Children.Remove(Control); parent.Children.Add(grid); grid.Children.Add(Control); } }; } } }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { iosButton = (UIButton) Control; formsElement = (CustomImageButton)this.Element; if (formsElement.ImageName != null) { iosButton.SetBackgroundImage(UIImage.FromBundle(formsElement.ImageName), UIControlState.Normal); } /* if (Convert.ToString(callingElement.TextOrientation) == CustomLocalization.GetString(LEFT,string.Empty)) { nativeButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left; } else if (Convert.ToString(callingElement.TextOrientation) == CustomLocalization.GetString(RIGHT, string.Empty)) { nativeButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right; } else { nativeButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; }*/ } }
protected override void OnElementChanged (ElementChangedEventArgs<Picker> e) { base.OnElementChanged (e); if (this.Control != null) { this.Control.Visibility = ViewStates.Invisible; } }
protected override void OnElementChanged (ElementChangedEventArgs<Page> e) { base.OnElementChanged (e); if (e.OldElement != null || Element == null) return; try { activity = this.Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false); cameraType = CameraFacing.Back; textureView = view.FindViewById<TextureView> (Resource.Id.textureView); textureView.SurfaceTextureListener = this; takePhotoButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.takePhotoButton); takePhotoButton.Click += TakePhotoButtonTapped; switchCameraButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.switchCameraButton); switchCameraButton.Click += SwitchCameraButtonTapped; toggleFlashButton = view.FindViewById<global::Android.Widget.Button> (Resource.Id.toggleFlashButton); toggleFlashButton.Click += ToggleFlashButtonTapped; AddView (view); } catch (Exception ex) { //Xamarin.Insights.Report (ex); } }
protected override void OnElementChanged(ElementChangedEventArgs<Image> e) { base.OnElementChanged(e); if (e.NewElement != null) { var s = e.NewElement.Source as FileImageSource; if (s != null) { var fileName = s.File; string ci = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString(); if (ci == "pt-BR") { // use the complete string 'as is' } else if (ci == "zh-CN") { ci = "zh-Hans"; // we could have named the image directories differently, but this keeps them consisent with RESX naming } else if (ci == "zh-TW" || ci == "zh-HK") { ci = "zh-Hant"; } else { // for all others, just use the two-character language code ci = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; } e.NewElement.Source = Path.Combine("Assets/" + ci + "/" + fileName); } } }
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged(e); var app = (MixRadioActivity.App.Current as MixRadioActivity.App); WebAuthenticationBroker.AuthenticateAndContinue(app.ActivityViewModel.GetAuthUri(), new Uri(ApiKeys.OAuthRedirectUrl)); }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (Control != null) { var button = (CustomButton)e.NewElement; button.SizeChanged += (s, args) => { // Estado normal _normal = new GradientDrawable(); _normal.SetColor(Android.Graphics.Color.DarkBlue); _normal.SetCornerRadius(100); // Estado pulsado _pressed = new GradientDrawable(); _pressed.SetColor(Android.Graphics.Color.DarkCyan); _pressed.SetCornerRadius(100); var sld = new StateListDrawable(); sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed); sld.AddState(new int[] { }, _normal); Control.SetBackgroundDrawable(sld); Control.SetTextSize(ComplexUnitType.Px, 60); Control.SetTextColor(Android.Graphics.Color.Silver); }; } }
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) { base.OnElementChanged(e); var activity = Context as Activity; var auth = new OAuth2Authenticator( clientId: "actioncenterapp", // OAuth2 client id scope: "actioncenter", // the scopes for the particular API you're accessing, delimited by "+" symbols authorizeUrl: new Uri("https://idsat.nwpsmart.com/identity/connect/authorize"), // the auth URL for the service redirectUrl: new Uri("https://actioncenterapp/callback/")); // the redirect URL for the service auth.Completed += (sender, eventArgs) => { if (eventArgs.IsAuthenticated) { App.SaveToken(eventArgs.Account.Properties["access_token"]); var page = Element as LoginPage; page?.NavigateToHome(); } else { // The user cancelled } }; activity.StartActivity(auth.GetUI(activity)); }
protected override void OnElementChanged (ElementChangedEventArgs<Page> e) { base.OnElementChanged (e); // Retrieve any stored account information var accounts = AccountStore.Create (Context).FindAccountsForService (App.AppName); var account = accounts.FirstOrDefault (); if (account == null) { if (!isShown) { isShown = true; // Initialize the object that communicates with the OAuth service var auth = new OAuth2Authenticator ( Constants.ClientId, Constants.ClientSecret, Constants.Scope, new Uri (Constants.AuthorizeUrl), new Uri (Constants.RedirectUrl), new Uri (Constants.AccessTokenUrl)); // Register an event handler for when the authentication process completes auth.Completed += OnAuthenticationCompleted; // Display the UI var activity = Context as Activity; activity.StartActivity (auth.GetUI (activity)); } } else { if (!isShown) { App.User.Email = account.Username; App.SuccessfulLoginAction.Invoke (); } } }
/// <inheritdoc/> protected override void OnElementChanged(ElementChangedEventArgs<View> e) { base.OnElementChanged(e); if (e.OldElement != null || this.FormsMap == null || this.Map == null) return; this.Map.GetViewForAnnotation = this.GetViewForAnnotation; this.Map.OverlayRenderer = this.GetOverlayRenderer; this.Map.DidSelectAnnotationView += OnDidSelectAnnotationView; this.Map.RegionChanged += OnMapRegionChanged; this.Map.ChangedDragState += OnChangedDragState; this.Map.CalloutAccessoryControlTapped += OnMapCalloutAccessoryControlTapped; this.Map.AddGestureRecognizer(new UILongPressGestureRecognizer(this.OnMapLongPress)); this.Map.AddGestureRecognizer(new UITapGestureRecognizer(this.OnMapClicked)); if (this.FormsMap.CustomPins != null) { this.UpdatePins(); this.FormsMap.CustomPins.CollectionChanged += OnCollectionChanged; } this.SetMapCenter(); this.UpdateRoutes(); this.UpdateLines(); this.UpdateCircles(); this.UpdatePolygons(); this.FormsMap.PropertyChanged += OnMapPropertyChanged; }
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e) { base.OnElementChanged(e); if (Control != null) { Control.Layer.BorderColor = UIColor.White.CGColor; Control.Layer.BorderWidth = 1f; Control.BorderStyle = UITextBorderStyle.Line; Control.Layer.CornerRadius = 0; Control.ClipsToBounds = true; switch (e.NewElement.ClassId) { case "1": Control.LeftView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("name.png")); break; case "3": Control.LeftView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("email.png")); break; case "4": Control.LeftView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("password.png")); break; case "5": Control.LeftView = new UIImageView(UIImage.FromFile("Usrename.png")); break; case "6": Control.LeftView = new UIImageView(UIImage.FromFile("password.png")); //UIColor.FromPatternImage(UIImage.FromFile("password.png")); break; default: break; } } }
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.View> e) { base.OnElementChanged (e); //Get LayoutInflater and inflate from axml //Important note, this project utilizes a layout-land folder in the Resources folder //Android will use this folder with layout files for Landscape Orientations //This is why we don't have to worry about the layout of the play button, it doesn't exist in landscape layout file!!! var activity = Context as Activity; var viewHolder = activity.LayoutInflater.Inflate (Resource.Layout.Main, this, false); view = viewHolder; AddView (view); //Get and set Views videoView = FindViewById<VideoView> (Resource.Id.SampleVideoView); playButton = FindViewById<Android.Widget.Button> (Resource.Id.PlayVideoButton); //Give some color to the play button, but not important playButton.SetBackgroundColor (Android.Graphics.Color.Aqua); //uri for a free video var uri = Android.Net.Uri.Parse ("https://www.dropbox.com/s/hi45psyy0wq9560/PigsInAPolka1943.mp4?dl=1"); //Set the videoView with our uri, this could also be a local video on device videoView.SetVideoURI (uri); //Assign click event on our play button to play the video playButton.Click += PlayVideo; }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); LoginToFacebook(false); }
protected override void OnElementChanged(ElementChangedEventArgs <ItemsView> elementChangedEvent) { base.OnElementChanged(elementChangedEvent); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { var mapModel = (Map)e.OldElement; MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName); ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnPinCollectionChanged; foreach (Pin pin in mapModel.Pins) { pin.PropertyChanged -= PinOnPropertyChanged; } ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged -= OnMapElementCollectionChanged; foreach (MapElement mapElement in mapModel.MapElements) { mapElement.PropertyChanged -= MapElementPropertyChanged; } } if (e.NewElement != null) { var mapModel = (Map)e.NewElement; if (Control == null) { MKMapView mapView = null; #if __MOBILE__ if (FormsMaps.IsiOs9OrNewer) { // See if we've got an MKMapView available in the pool; if so, use it mapView = MapPool.Get(); } #endif if (mapView == null) { // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool, // create a new one mapView = new MKMapView(RectangleF.Empty); } SetNativeControl(mapView); mapView.GetViewForAnnotation = GetViewForAnnotation; mapView.OverlayRenderer = GetViewForOverlay; mapView.DidSelectAnnotationView += MkMapViewOnAnnotationViewSelected; mapView.RegionChanged += MkMapViewOnRegionChanged; #if __MOBILE__ mapView.AddGestureRecognizer(_mapClickedGestureRecognizer = new UITapGestureRecognizer(OnMapClicked)); #endif } MessagingCenter.Subscribe <Map, MapSpan>(this, MoveMessageName, (s, a) => MoveToRegion(a), mapModel); if (mapModel.LastMoveToRegion != null) { MoveToRegion(mapModel.LastMoveToRegion, false); } UpdateTrafficEnabled(); UpdateMapType(); UpdateIsShowingUser(); UpdateHasScrollEnabled(); UpdateHasZoomEnabled(); ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged += OnPinCollectionChanged; OnPinCollectionChanged(mapModel.Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); ((ObservableCollection <MapElement>)mapModel.MapElements).CollectionChanged += OnMapElementCollectionChanged; OnMapElementCollectionChanged(mapModel.MapElements, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } }
protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e) { base.OnElementChanged(e); Control.Background = null; }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); Element.Layout(new Rectangle(Element.X + 50, Element.Y, Element.Width, Element.Height)); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); // For XAML Previewer or FormsGoogleMaps.Init not called. if (!FormsGoogleMaps.IsInitialized) { var label = new UILabel() { Text = "Xamarin.Forms.GoogleMaps", BackgroundColor = Color.Teal.ToUIColor(), TextColor = Color.Black.ToUIColor(), TextAlignment = UITextAlignment.Center }; SetNativeControl(label); return; } var oldMapView = (MapView)Control; if (e.OldElement != null) { var oldMapModel = (Map)e.OldElement; oldMapModel.OnSnapshot -= OnSnapshot; _cameraLogic.Unregister(); if (oldMapView != null) { oldMapView.CoordinateLongPressed -= CoordinateLongPressed; oldMapView.CoordinateTapped -= CoordinateTapped; oldMapView.CameraPositionChanged -= CameraPositionChanged; oldMapView.DidTapMyLocationButton = null; } } if (e.NewElement != null) { var mapModel = (Map)e.NewElement; if (Control == null) { SetNativeControl(new MapView(RectangleF.Empty)); var mkMapView = (MapView)Control; mkMapView.CameraPositionChanged += CameraPositionChanged; mkMapView.CoordinateTapped += CoordinateTapped; mkMapView.CoordinateLongPressed += CoordinateLongPressed; mkMapView.DidTapMyLocationButton = DidTapMyLocation; } _cameraLogic.Register(Map, NativeMap); Map.OnSnapshot += OnSnapshot; //_cameraLogic.MoveCamera(mapModel.InitialCameraUpdate); //_ready = true; _uiSettingsLogic.Register(Map, NativeMap); UpdateMapType(); UpdateIsShowingUser(_uiSettingsLogic.MyLocationButtonEnabled); UpdateHasScrollEnabled(_uiSettingsLogic.ScrollGesturesEnabled); UpdateHasZoomEnabled(_uiSettingsLogic.ZoomGesturesEnabled); UpdateHasRotationEnabled(_uiSettingsLogic.RotateGesturesEnabled); UpdateIsTrafficEnabled(); UpdatePadding(); UpdateMapStyle(); UpdateMyLocationEnabled(); _uiSettingsLogic.Initialize(); foreach (var logic in Logics) { logic.Register(oldMapView, (Map)e.OldElement, NativeMap, Map); logic.RestoreItems(); logic.OnMapPropertyChanged(new PropertyChangedEventArgs(Map.SelectedPinProperty.PropertyName)); } } }
protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e) { base.OnElementChanged(e); var activity = Context.GetActivity(); var isDesigner = Context.IsDesignerContext(); var themeContext = isDesigner ? Context : activity; if (e.OldElement != null) { ((IPageController)e.OldElement).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged; } if (e.NewElement != null) { if (IsBottomTabPlacement) { if (_relativeLayout == null) { _relativeLayout = new AWidget.RelativeLayout(Context) { LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), }; if (_bottomNavigationView != null) { _relativeLayout.RemoveView(_bottomNavigationView); _bottomNavigationView.SetOnNavigationItemSelectedListener(null); } var bottomNavigationViewLayoutParams = new AWidget.RelativeLayout.LayoutParams( LayoutParams.MatchParent, LayoutParams.WrapContent); bottomNavigationViewLayoutParams.AddRule(AWidget.LayoutRules.AlignParentBottom); _bottomNavigationView = new BottomNavigationView(Context) { LayoutParameters = bottomNavigationViewLayoutParams, Id = Platform.GenerateViewId() }; var viewPagerParams = new AWidget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); viewPagerParams.AddRule(AWidget.LayoutRules.Above, _bottomNavigationView.Id); FormsViewPager pager = _viewPager = CreateFormsViewPager(themeContext, e.NewElement); pager.Id = Platform.GenerateViewId(); pager.AddOnPageChangeListener(this); _relativeLayout.AddView(pager, viewPagerParams); _relativeLayout.AddView(_bottomNavigationView, bottomNavigationViewLayoutParams); AddView(_relativeLayout); } } else { if (_tabLayout == null) { TabLayout tabs; if (FormsAppCompatActivity.TabLayoutResource > 0 && !isDesigner) { tabs = _tabLayout = activity.LayoutInflater.Inflate(FormsAppCompatActivity.TabLayoutResource, null).JavaCast <TabLayout>(); } else { tabs = _tabLayout = new TabLayout(themeContext) { TabMode = TabLayout.ModeFixed, TabGravity = TabLayout.GravityFill } }; FormsViewPager pager = _viewPager = CreateFormsViewPager(themeContext, e.NewElement); pager.Id = Platform.GenerateViewId(); pager.AddOnPageChangeListener(this); AddView(pager); AddView(tabs); } } OnChildrenCollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); TabbedPage tabbedPage = e.NewElement; if (tabbedPage.CurrentPage != null) { ScrollToCurrentPage(); } _previousPage = tabbedPage.CurrentPage; ((IPageController)tabbedPage).InternalChildren.CollectionChanged += OnChildrenCollectionChanged; UpdateBarBackgroundColor(); UpdateBarTextColor(); UpdateItemIconColor(); if (!isDesigner) { UpdateSwipePaging(); UpdateOffscreenPageLimit(); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); Control?.SetBackgroundColor(Android.Graphics.Color.Transparent); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); Linkify.AddLinks(Control, MatchOptions.All); }
protected override void OnElementChanged(ElementChangedEventArgs <DemoListCellView> e) { SetBackgroundResource(Resource.Drawable.list_selector_pressed); base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Entry> e) { base.OnElementChanged(e); if (e.NewElement != null) { formControl = (Element as EntryUnderlineControl); var editText = (EditText)Control; editText.EditorAction += (obj, act) => { formControl?.NextFocus?.Invoke(); }; editText.Touch += (a, aa) => { aa.Handled = false; var w = editText.Width; var wl = editText.CompoundPaddingLeft; var wr = w - editText.CompoundPaddingRight; var x = aa.Event.GetX(); if (wr < x && aa.Event.Action == Android.Views.MotionEventActions.Down) { if (/*formControl.IsPassword * &&*/formControl.PasswordRevealEnabled && !string.IsNullOrEmpty(formControl.PasswordRevealIcon) && !string.IsNullOrEmpty(formControl.PasswordHideIcon)) { formControl.IsPassword = !formControl.IsPassword; var rightDrawable = formControl.IsPassword == true?GetDrawable(formControl.PasswordRevealIcon) : GetDrawable(formControl.PasswordHideIcon); editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(formControl.Icon)?.Target as Drawable, null, rightDrawable?.Target as Drawable, null); editText.CompoundDrawablePadding = 20; } } }; if (formControl != null && formControl.IsPassword && !string.IsNullOrEmpty(formControl.PasswordRevealIcon) && !string.IsNullOrEmpty(formControl.PasswordHideIcon) && formControl.PasswordRevealEnabled) { var size = editText.TextSize; var rightDrawable = formControl.IsPassword == true?GetDrawable(formControl.PasswordRevealIcon) : null; editText.SetCompoundDrawablesWithIntrinsicBounds(GetDrawable(formControl.Icon)?.Target as Drawable, null, rightDrawable?.Target as Drawable, null); editText.CompoundDrawablePadding = 20; editText.Gravity = Android.Views.GravityFlags.Bottom; } if (!formControl.PasswordRevealEnabled && !string.IsNullOrEmpty(formControl.ClearEntryIcon) && formControl.ClearEntryEnabled) { var iconResource = formControl.ClearEntryIcon.Replace(".png", string.Empty).Replace(".jpg", string.Empty); var clearIcon = GetResourceIdByName(iconResource); editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, clearIcon, 0); editText.SetOnTouchListener(new OnDrawableTouchListener()); } if (formControl != null && formControl.EntryColor != null) { editText.Background.Mutate().SetColorFilter(formControl.EntryColor.ToAndroid(), Android.Graphics.PorterDuff.Mode.SrcAtop); } if ((Control != null) & (e.NewElement != null)) { var entryExt = (e.NewElement as EntryUnderlineControl); Control.ImeOptions = entryExt.ReturnKeyType.GetValueFromDescription(); Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), Control.ImeOptions); } if (!string.IsNullOrEmpty(e.NewElement?.StyleId) && Control != null) { var fileName = e.NewElement.StyleId + ".ttf"; if (Resources.Assets.List("").Contains(fileName)) { var font = Android.Graphics.Typeface.CreateFromAsset(context.ApplicationContext.Assets, fileName); Control.Typeface = font; } } } }
protected override void OnElementChanged(ElementChangedEventArgs <BoxView> e) { base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <CardsView> e) { base.OnElementChanged(e); _panStarted = false; }
protected override void OnElementChanged(ElementChangedEventArgs <AppleSignInButton> e) { base.OnElementChanged(e); if (e.OldElement != null) { // Cleanup if (Is13) { if (button != null) { button.TouchUpInside -= Button_TouchUpInside; } } else { if (oldButton != null) { oldButton.TouchUpInside -= Button_TouchUpInside; } } } if (e.NewElement != null) { // Create if (Is13) { if (button == null) { button = (ASAuthorizationAppleIdButton)CreateNativeControl(); button.TouchUpInside += Button_TouchUpInside; SetNativeControl(button); } } else { //if (oldButton == null) //{ // oldButton = (UIButton)CreateNativeControl(); // oldButton.TouchUpInside += Button_TouchUpInside; // oldButton.Layer.CornerRadius = 4; // oldButton.Layer.BorderWidth = 1; // oldButton.ClipsToBounds = true; // oldButton.SetTitle(" " + Element.Text, UIControlState.Normal); // switch (Element.ButtonStyle) // { // case AppleSignInButtonStyle.Black: // oldButton.BackgroundColor = UIColor.Black; // oldButton.SetTitleColor(UIColor.White, UIControlState.Normal); // oldButton.Layer.BorderColor = UIColor.Black.CGColor; // break; // case AppleSignInButtonStyle.White: // oldButton.BackgroundColor = UIColor.White; // oldButton.SetTitleColor(UIColor.Black, UIControlState.Normal); // oldButton.Layer.BorderColor = UIColor.White.CGColor; // break; // case AppleSignInButtonStyle.WhiteOutline: // oldButton.BackgroundColor = UIColor.White; // oldButton.SetTitleColor(UIColor.Black, UIControlState.Normal); // oldButton.Layer.BorderColor = UIColor.Black.CGColor; // break; // } // SetNativeControl(oldButton); //} } } }
/// <summary> /// Handles the initial drawing of the button. /// </summary> /// <param name="e">Information on the <see cref="ImageButton" />.</param> protected override async void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); await AssignContent(); }
protected override void OnElementChanged(ElementChangedEventArgs <Image> e) { base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { base.OnElementChanged(e); Control.Gravity = GravityFlags.Center; Control.TextSize = 12; }
protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e) { if (e.NewElement != null) { if (Control == null) { var entry = CreateNativeControl(); entry.EditingDidBegin += OnStarted; entry.EditingDidEnd += OnEnded; _picker = new UIDatePicker { Mode = UIDatePickerMode.Time, TimeZone = new NSTimeZone("UTC") }; if (Forms.IsiOS14OrNewer) { _picker.PreferredDatePickerStyle = UIKit.UIDatePickerStyle.Wheels; } var width = UIScreen.MainScreen.Bounds.Width; var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44)) { BarStyle = UIBarStyle.Default, Translucent = true }; var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => { UpdateElementTime(); entry.ResignFirstResponder(); }); toolbar.SetItems(new[] { spacer, doneButton }, false); entry.InputView = _picker; entry.InputAccessoryView = toolbar; entry.InputView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight; entry.InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight; entry.InputAssistantItem.LeadingBarButtonGroups = null; entry.InputAssistantItem.TrailingBarButtonGroups = null; _defaultTextColor = entry.TextColor; _useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _picker.ValueChanged += OnValueChanged; entry.AccessibilityTraits = UIAccessibilityTrait.Button; SetNativeControl(entry); } UpdateFont(); UpdateTime(); UpdateTextColor(); UpdateCharacterSpacing(); UpdateFlowDirection(); } base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { base.OnElementChanged(e); EditorsScrollingHelper.AttachToControl(Control, this); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); Control.SetMaxLines(1000); }
protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); try { CustomLabel element = Element as CustomLabel; if (e.NewElement != null) { element = Element as CustomLabel; } else { element = e.OldElement as CustomLabel; } if (Control != null) { var label = (UILabel)Control; label.ExclusiveTouch = true; //Control.ExclusiveTouch = true; //var element = Element as CustomLabel; if (!string.IsNullOrWhiteSpace(element.CustomFontColor)) { //Control.TextColor = Color.FromHex(element.CustomFontColor).ToUIColor(); //Control.TextColor = Color.FromHex("#00A6CC").ToUIColor(); //Control.TextColor = Color.FromHex(element.CustomFontColor).ToCGColor(); } //Control.TextColor = UIColor.Black; //for place holder //var entry1 = new Entry(); //Control.Layer.BorderColor = Color.FromHex("#0000").ToCGColor(); //Control.Layer.BorderWidth = 0; //entry1.Layer.BorderWidth = 1f; // to set underline label if (element.ShallUnderLine == true) { nint startind = 0, charLength = 0; startind = element.StartIndex; //var label = (UILabel)Control; var text = (NSMutableAttributedString)label.AttributedText; if (element.NoOfChar == 0 && element.EndIndex == 0) { charLength = text.Length; } else if (element.EndIndex != 0 && element.NoOfChar != 0) { charLength = element.NoOfChar; } else if (element.EndIndex == 0) { charLength = element.NoOfChar; } else if (element.NoOfChar == 0) { charLength = element.EndIndex - element.StartIndex; } else { charLength = text.Length; } var range = new NSRange(startind, charLength); text.AddAttribute(UIStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range); } else if (element.ShallUnderLine == true && element.ShallUseHTMLOnly == false) { } else { } //for font size and font formats var fontSizes = 16.0; if (element.FontSize == 0 || element.FontSize == null) { } else { fontSizes = element.FontSize; } uint fontSize = (uint)fontSizes; if (element.FontFamily == "HelveticaReg") { label.Font = UIFont.FromName("HelveticaRegular.ttf", fontSize); //Control.Font = UIFont.FromName("HelveticaRegular.ttf", fontSize); } else if (element.FontFamily == "Helvitica77B") { label.Font = UIFont.FromName("HelveticaNeueIt77BoldCondensed.ttf", fontSize); //Control.Font = UIFont.FromName("HelveticaNeueIt77BoldCondensed.ttf", fontSize); } else if (element.FontFamily == "Helvitica57B") { label.Font = UIFont.FromName("HelveticaLT57Condensed.ttf", fontSize); //Control.Font = UIFont.FromName("HelveticaLT57Condensed.ttf", fontSize); } else { } if (element.IsHTMLText == true) { var attr = new NSAttributedStringDocumentAttributes(); var nsError = new NSError(); attr.DocumentType = NSDocumentType.HTML; var myHtmlData = NSData.FromString(element.Text, NSStringEncoding.Unicode); this.Control.AttributedText = new NSAttributedString(myHtmlData, attr, ref nsError); } } } catch (Exception ex) { var msg = ex.Message; } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); Control?.SetBackgroundColor(global::Android.Graphics.Color.White); }