Hi everyone,
I am relatively new to Xamarin, Xamarin forms and I am currently trying to write my own Custom Renderer For the Xamarin.Form.Picker so that I can style each Item in the picker.
At the moment I am focusing on Windows phone and I have got as far as creating a new Item Template in Xaml and mapping it to the Native control but the problem I'm having is that the Text isn't being mapped to the values that I have populated the Xamarin.Form.Picker with.
Here is my code:
Xaml:
<Application.Resources>
<DataTemplate x:Key="ListItemTemplate">
<StackPanel Background="Azure">
<TextBlock Text="{Binding}" Foreground="Black"></TextBlock>
</StackPanel>
</DataTemplate>
</Application.Resources>
CustomRenderer:
public class CustomPickerRenderer : PickerRenderer
{
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
switch (e.PropertyName)
{
case "Renderer":
this.Control.FullModeItemTemplate = (System.Windows.DataTemplate)App.Current.Resources["ListItemTemplate"];
this.Control.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
break;
}
}
}
The Image of Result:
My Question is how do I get the values which are attached to the Xamarin.Forms.Picker to be displayed with my custom Style or is it that I can't use custom styles At this time.
Thank you all in advance
Pete.