maui-linux/Xamarin.Forms.Platform.UAP/PickerRenderer.cs

272 строки
7.5 KiB
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
using System;
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
2016-03-22 23:02:25 +03:00
using System.ComponentModel;
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
using System.Linq;
2016-03-22 23:02:25 +03:00
using System.Threading.Tasks;
using Windows.UI.Core;
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
using Windows.UI.Text;
using Windows.UI.Xaml;
2016-03-22 23:02:25 +03:00
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Xamarin.Forms.Internals;
using WSelectionChangedEventArgs = Windows.UI.Xaml.Controls.SelectionChangedEventArgs;
2016-03-22 23:02:25 +03:00
namespace Xamarin.Forms.Platform.UWP
{
public class PickerRenderer : ViewRenderer<Picker, FormsComboBox>
{
bool _fontApplied;
2016-03-22 23:02:25 +03:00
bool _isAnimating;
Brush _defaultBrush;
FontFamily _defaultFontFamily;
2016-03-22 23:02:25 +03:00
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (Control != null)
{
_isAnimating = false;
Control.SelectionChanged -= OnControlSelectionChanged;
Control.DropDownOpened -= OnDropDownOpenStateChanged;
Control.DropDownClosed -= OnDropDownOpenStateChanged;
Control.OpenAnimationCompleted -= ControlOnOpenAnimationCompleted;
Control.Loaded -= ControlOnLoaded;
2016-03-22 23:02:25 +03:00
}
}
base.Dispose(disposing);
}
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
if (e.NewElement != null)
{
if (Control == null)
{
SetNativeControl(new FormsComboBox());
Control.SelectionChanged += OnControlSelectionChanged;
Control.DropDownOpened += OnDropDownOpenStateChanged;
Control.DropDownClosed += OnDropDownOpenStateChanged;
Control.OpenAnimationCompleted += ControlOnOpenAnimationCompleted;
Control.ClosedAnimationStarted += ControlOnClosedAnimationStarted;
Control.Loaded += ControlOnLoaded;
2016-03-22 23:02:25 +03:00
}
VisualStateManager phase 1 (#1405) * Port from old VSM branch * Add PS and notes * Checkpoint: entry text UWP mostly working, need to check on background colors * Remove irrelevant samples from the EntryDisabledStatesGallery Make Background color work on UWP Entry with VSM * Add platform specific for disabling legacy colors on Android * Add OnPlatform example to visual state manager gallery * Add example OnIdiom in Visual State Manager * Add platform specific for disabling legacy color mode on iOS Entry * Add gallery for Button disabled states Handling legacy colors for Buttons on Android * Split out disabled states galleries; disabled legacy handling for Picker * TimePicker disabled states * DatePicker color management on Android * Color management for pre-AppCompat button * Button legacy color handling on iOS * Consolidate Platform Specifics; legacy colors working for iOS Picker and DatePicker * Fix broken search bar color management SearchBar color management working with VSM Add test page for SearchBar disabled color management Consolidate legacy color management check code into extension method on Android * Legacy color management for Editor on Android * Fix legacy color stuff for SearchBar Cancel button on iOS * C# 7 cleanup * Add colors for Cancel Button * Make sure VisualStateGroup collections set by styles are distinct objects * Validation example * Make common state names consts * Make the Windows VSM and Forms VSM work together * Update galleries for Windows * Make new methods internal * Split gallery classes and add more explanation to validation example * Remove debugging statements * Add a quick code-only example * Make legacy color management work for fast button renderer * Remove old TODO * Update docs * Move RunTimeNamePropertyAttribute to Xamarin.Forms.Xaml namespace * Verify XF namespace when looking for VisualState * Use nameof * Make common states constants public * Cast VisualElement directly so it crashes if the property is set on the wrong type * Collection -> IList for VisualStateManager * Setting fromStyle to true * Remove extraneous `private set` * Seal VSM classes * Use constraints instead of == * Add teardown method; use constraints rather than == * Remove null checking with GetVisualStateGroups * Don't explicitly initialize collections on elements * Actually, turns out that fromStyle:false *was* correct * Direct casts * Use GetIsDefault check in GoToState * Validate parents in FindTypeForVisualState * Validate group and state names on Add * Fixed check for setter collection * Fix issues with "duplicate" names when VisualStateGroups declared directly on VisualElements * Add gallery example for VSGs directly on VisualElements * Update docs * Fix bug where initial TextColor isn't set for FastRenderer Button * Move to explicit VisualStateGroupList in Setter * Fix return types for unit tests * Using string.CompareOrdinal in GetState * Update docs * Add check for null/empty VisualState Name properties
2018-01-05 12:11:51 +03:00
else
{
WireUpFormsVsm();
}
2016-03-22 23:02:25 +03:00
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
Control.ItemsSource = GetItems(Element.Items);
2016-03-22 23:02:25 +03:00
UpdateTitle();
UpdateSelectedIndex();
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
UpdateCharacterSpacing();
2016-03-22 23:02:25 +03:00
}
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Picker.SelectedIndexProperty.PropertyName)
UpdateSelectedIndex();
else if (e.PropertyName == Picker.TitleProperty.PropertyName || e.PropertyName == Picker.TitleColorProperty.PropertyName)
2016-03-22 23:02:25 +03:00
UpdateTitle();
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
else if (e.PropertyName == Picker.CharacterSpacingProperty.PropertyName)
UpdateCharacterSpacing();
else if (e.PropertyName == Picker.TextColorProperty.PropertyName)
UpdateTextColor();
else if (e.PropertyName == Picker.FontAttributesProperty.PropertyName || e.PropertyName == Picker.FontFamilyProperty.PropertyName || e.PropertyName == Picker.FontSizeProperty.PropertyName)
UpdateFont();
}
void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
VisualStateManager phase 1 (#1405) * Port from old VSM branch * Add PS and notes * Checkpoint: entry text UWP mostly working, need to check on background colors * Remove irrelevant samples from the EntryDisabledStatesGallery Make Background color work on UWP Entry with VSM * Add platform specific for disabling legacy colors on Android * Add OnPlatform example to visual state manager gallery * Add example OnIdiom in Visual State Manager * Add platform specific for disabling legacy color mode on iOS Entry * Add gallery for Button disabled states Handling legacy colors for Buttons on Android * Split out disabled states galleries; disabled legacy handling for Picker * TimePicker disabled states * DatePicker color management on Android * Color management for pre-AppCompat button * Button legacy color handling on iOS * Consolidate Platform Specifics; legacy colors working for iOS Picker and DatePicker * Fix broken search bar color management SearchBar color management working with VSM Add test page for SearchBar disabled color management Consolidate legacy color management check code into extension method on Android * Legacy color management for Editor on Android * Fix legacy color stuff for SearchBar Cancel button on iOS * C# 7 cleanup * Add colors for Cancel Button * Make sure VisualStateGroup collections set by styles are distinct objects * Validation example * Make common state names consts * Make the Windows VSM and Forms VSM work together * Update galleries for Windows * Make new methods internal * Split gallery classes and add more explanation to validation example * Remove debugging statements * Add a quick code-only example * Make legacy color management work for fast button renderer * Remove old TODO * Update docs * Move RunTimeNamePropertyAttribute to Xamarin.Forms.Xaml namespace * Verify XF namespace when looking for VisualState * Use nameof * Make common states constants public * Cast VisualElement directly so it crashes if the property is set on the wrong type * Collection -> IList for VisualStateManager * Setting fromStyle to true * Remove extraneous `private set` * Seal VSM classes * Use constraints instead of == * Add teardown method; use constraints rather than == * Remove null checking with GetVisualStateGroups * Don't explicitly initialize collections on elements * Actually, turns out that fromStyle:false *was* correct * Direct casts * Use GetIsDefault check in GoToState * Validate parents in FindTypeForVisualState * Validate group and state names on Add * Fixed check for setter collection * Fix issues with "duplicate" names when VisualStateGroups declared directly on VisualElements * Add gallery example for VSGs directly on VisualElements * Update docs * Fix bug where initial TextColor isn't set for FastRenderer Button * Move to explicit VisualStateGroupList in Setter * Fix return types for unit tests * Using string.CompareOrdinal in GetState * Update docs * Add check for null/empty VisualState Name properties
2018-01-05 12:11:51 +03:00
WireUpFormsVsm();
// The defaults from the control template won't be available
// right away; we have to wait until after the template has been applied
_defaultBrush = Control.Foreground;
_defaultFontFamily = Control.FontFamily;
UpdateFont();
UpdateTextColor();
2016-03-22 23:02:25 +03:00
}
VisualStateManager phase 1 (#1405) * Port from old VSM branch * Add PS and notes * Checkpoint: entry text UWP mostly working, need to check on background colors * Remove irrelevant samples from the EntryDisabledStatesGallery Make Background color work on UWP Entry with VSM * Add platform specific for disabling legacy colors on Android * Add OnPlatform example to visual state manager gallery * Add example OnIdiom in Visual State Manager * Add platform specific for disabling legacy color mode on iOS Entry * Add gallery for Button disabled states Handling legacy colors for Buttons on Android * Split out disabled states galleries; disabled legacy handling for Picker * TimePicker disabled states * DatePicker color management on Android * Color management for pre-AppCompat button * Button legacy color handling on iOS * Consolidate Platform Specifics; legacy colors working for iOS Picker and DatePicker * Fix broken search bar color management SearchBar color management working with VSM Add test page for SearchBar disabled color management Consolidate legacy color management check code into extension method on Android * Legacy color management for Editor on Android * Fix legacy color stuff for SearchBar Cancel button on iOS * C# 7 cleanup * Add colors for Cancel Button * Make sure VisualStateGroup collections set by styles are distinct objects * Validation example * Make common state names consts * Make the Windows VSM and Forms VSM work together * Update galleries for Windows * Make new methods internal * Split gallery classes and add more explanation to validation example * Remove debugging statements * Add a quick code-only example * Make legacy color management work for fast button renderer * Remove old TODO * Update docs * Move RunTimeNamePropertyAttribute to Xamarin.Forms.Xaml namespace * Verify XF namespace when looking for VisualState * Use nameof * Make common states constants public * Cast VisualElement directly so it crashes if the property is set on the wrong type * Collection -> IList for VisualStateManager * Setting fromStyle to true * Remove extraneous `private set` * Seal VSM classes * Use constraints instead of == * Add teardown method; use constraints rather than == * Remove null checking with GetVisualStateGroups * Don't explicitly initialize collections on elements * Actually, turns out that fromStyle:false *was* correct * Direct casts * Use GetIsDefault check in GoToState * Validate parents in FindTypeForVisualState * Validate group and state names on Add * Fixed check for setter collection * Fix issues with "duplicate" names when VisualStateGroups declared directly on VisualElements * Add gallery example for VSGs directly on VisualElements * Update docs * Fix bug where initial TextColor isn't set for FastRenderer Button * Move to explicit VisualStateGroupList in Setter * Fix return types for unit tests * Using string.CompareOrdinal in GetState * Update docs * Add check for null/empty VisualState Name properties
2018-01-05 12:11:51 +03:00
void WireUpFormsVsm()
{
if (Element.UseFormsVsm())
{
InterceptVisualStateManager.Hook(Control.GetFirstDescendant<Windows.UI.Xaml.Controls.Grid>(), Control, Element);
}
}
2016-03-22 23:02:25 +03:00
void ControlOnClosedAnimationStarted(object sender, EventArgs eventArgs)
{
if (!Control.IsFullScreen)
{
// Start refreshing while the control's closing animation runs;
// OnDropDownOpenStateChanged will take care of stopping the refresh
StartAnimationRefresh();
}
}
void ControlOnOpenAnimationCompleted(object sender, EventArgs eventArgs)
{
_isAnimating = false;
if (!Control.IsFullScreen)
{
// Force a final redraw after the closing animation has completed
((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
2016-03-22 23:02:25 +03:00
}
}
void OnControlSelectionChanged(object sender, WSelectionChangedEventArgs e)
2016-03-22 23:02:25 +03:00
{
if (Element != null)
Element.SelectedIndex = Control.SelectedIndex;
}
void OnDropDownOpenStateChanged(object sender, object o)
{
if (Control.IsDropDownOpen)
{
if (Control.IsOpeningAnimated && !Control.IsFullScreen)
{
// Start running the animation refresh;
// ControlOnOpenAnimationCompleted will take care of stopping it
StartAnimationRefresh();
}
else
{
((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
2016-03-22 23:02:25 +03:00
}
}
else
{
// The ComboBox is now closed; if we were animating the closure, stop
_isAnimating = false;
// and force the final redraw
((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged);
2016-03-22 23:02:25 +03:00
}
}
/// <summary>
/// Forces redraw of the control during opening/closing animations to provide
/// a smoother sliding animation for the surrounding controls
/// Only applies on the phone and only when there are fewer than 6 items in the picker
/// </summary>
void StartAnimationRefresh()
{
_isAnimating = true;
Task.Factory.StartNew(async () =>
{
while (_isAnimating)
{
await Task.Delay(16);
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged));
2016-03-22 23:02:25 +03:00
}
});
}
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
void UpdateCharacterSpacing()
{
Control.CharacterSpacing = Element.CharacterSpacing.ToEm();
if (Control.Header is TextBlock header)
{
header.CharacterSpacing = Element.CharacterSpacing.ToEm();
}
if (Control.SelectedValue is TextBlock item)
{
item.CharacterSpacing = Element.CharacterSpacing.ToEm();
}
if(Control.ItemsSource is ObservableCollection<TextBlock> collection)
{
collection.ForEach(f=>f.CharacterSpacing = Control.CharacterSpacing);
}
}
TextBlock ConvertStrongToTextBlock(string text)
{
return new TextBlock{
Text = text,
CharacterSpacing = Control.CharacterSpacing
};
}
ObservableCollection<TextBlock> GetItems(IList<string> items)
{
return new ObservableCollection<TextBlock>(items.Select(ConvertStrongToTextBlock));
}
void UpdateFont()
{
if (Control == null)
return;
Picker picker = Element;
if (picker == null)
return;
bool pickerIsDefault = picker.FontFamily == null && picker.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Picker), true) && picker.FontAttributes == FontAttributes.None;
if (pickerIsDefault && !_fontApplied)
return;
if (pickerIsDefault)
{
// ReSharper disable AccessToStaticMemberViaDerivedType
Control.ClearValue(ComboBox.FontStyleProperty);
Control.ClearValue(ComboBox.FontSizeProperty);
Control.ClearValue(ComboBox.FontFamilyProperty);
Control.ClearValue(ComboBox.FontWeightProperty);
Control.ClearValue(ComboBox.FontStretchProperty);
// ReSharper restore AccessToStaticMemberViaDerivedType
}
else
{
Control.ApplyFont(picker);
}
_fontApplied = true;
}
2016-03-22 23:02:25 +03:00
void UpdateSelectedIndex()
{
Control.SelectedIndex = Element.SelectedIndex;
}
void UpdateTextColor()
{
Color color = Element.TextColor;
Control.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
}
2016-03-22 23:02:25 +03:00
void UpdateTitle()
{
if (!Element.IsSet(Picker.TitleColorProperty))
{
Control.HeaderTemplate = null;
[Enhancement] Implements CharacterSpacing (#5167) - fixes #4855 * TextElement.LetterSpacingProperty ButtonRenderer DatePickerRenderer EditorRenderer EntryRenderer.cs LabelRenderer PickerRenderer SearchBarRenderer TimePickerRenderer fix renderers LetterSpacingElement Extensions ToEm * iOS Picker * UWP * removal of an unnecessary condition * Remove ILetterSpacingElement.OnLetterSpacingChanged Fix for PickerRenderer for Android * Move LetterSpacing to TextElement * UWP * Span * Span and LetterSpacing * Tests * fixes for renderers * Renderers * LetterSpacingGallery * Android fixes * Extensions * delete macos code * iOS and UWP Renderers * Renderers for iOS * Picker.Items * UWP * fix merge * Renderers * iOS renderers * PickerRenderer.cs * Material * Material Renderer * Picker placeholder * InvalidateMeasure * Update Xamarin.Forms.Core/Span.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * Update Xamarin.Forms.Core/ITextElement.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org> * remove LetterSpacing tests * style * Rename LetterSpacing to CharacterSpacing * Update Xamarin.Forms.Controls/GalleryPages/CharacterSpacingGallery.xaml Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.Android/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialPickerRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialEditorRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update Xamarin.Forms.Material.iOS/MaterialButtonRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * SearchHandler * UAP CharacterSpacing * Update Xamarin.Forms.Core/Shell/SearchHandler.cs Co-Authored-By: Stephane Delcroix <stephane@delcroix.org>
2019-07-18 15:28:23 +03:00
Control.Header = new TextBlock
{
Text = Element.Title ?? string.Empty,
CharacterSpacing = Element.CharacterSpacing.ToEm(),
};
}
else
{
Control.Header = null;
Control.HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["ComboBoxHeader"];
Control.DataContext = Element;
}
2016-03-22 23:02:25 +03:00
}
}
}