Forum Xamarin.Forms

Custom renderer for picker in WP

Hey,

Some updates ago this stopped working (it used to work):

        if (Control != null)
        {
            Control.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
        }

Because "Foreground" is not available.
This won't work as well:

        if (Control != null)
        {
            ListPicker picker = Control as ListPicker;
            picker.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
        }

The renderer is correctly written. It used to work some updates ago.
How can i access the text color now?

Thanks in advance

Best Answers

Answers

  • PedroNeves.7715PedroNeves.7715 USMember ✭✭
    edited December 2015

    Thank you. I suppose it worked, as it does not throw an exception. The thing is, i do not know if it did. The picker just won't show up in Windows Phone. Is it somehow hidden or size 0 by default? Although i tried changing both of those properties in the custom renderer and it still does not show. This used to work...

    My custom renderer:

        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                ListPicker listPicker = ((ListPicker)((System.Windows.Controls.Grid)this.Control).Children[0]);
                listPicker.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
            }
        }
    

    The Forms classe:

    public class MyCustomPicker : BindablePicker
    {
    
    }
    

    The XAML:

          <mycontrols:MyCustomPicker Title="Optional"
                                       Grid.Column="2"
                                       HorizontalOptions="FillAndExpand"
                                       ItemsSource="{Binding Districts, Mode=TwoWay}"
                                       SelectedIndex="{Binding SelectedDistrict, Mode=TwoWay}"
                                       VerticalOptions="Center" />
    
  • PedroNeves.7715PedroNeves.7715 USMember ✭✭

    It disappears when i set the HorizontalOptions to FillAndExpand. Even in a blank page.

    Still, thanks ;)

Sign In or Register to comment.