diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WinRT.Phone | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT.Phone')
14 files changed, 2156 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/Forms.cs b/Xamarin.Forms.Platform.WinRT.Phone/Forms.cs new file mode 100644 index 00000000..8d06004c --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/Forms.cs @@ -0,0 +1,97 @@ +using System; +using System.Diagnostics; +using Windows.ApplicationModel.Activation; +using Windows.Phone.UI.Input; +using Windows.UI.ViewManagement; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; +using Xamarin.Forms.Platform.WinRT; + +namespace Xamarin.Forms +{ + public static class Forms + { + public static void Init (IActivatedEventArgs launchActivatedEventArgs) + { + if (s_isInitialized) + return; + + var accent = (SolidColorBrush)Windows.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"]; + Color.Accent = Color.FromRgba (accent.Color.R, accent.Color.G, accent.Color.B, accent.Color.A); + + Log.Listeners.Add (new DelegateLogListener ((c, m) => Debug.WriteLine (LogFormat, c, m))); + + Windows.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add (GetPhoneResources()); + + Device.OS = TargetPlatform.Windows; + Device.PlatformServices = new WindowsPhonePlatformServices (Window.Current.Dispatcher); + Device.Info = new WindowsDeviceInfo(); + Device.Idiom = TargetIdiom.Phone; + + Ticker.Default = new WindowsTicker(); + + ExpressionSearch.Default = new WindowsExpressionSearch(); + + Registrar.RegisterAll (new[] { + typeof (ExportRendererAttribute), + typeof (ExportCellAttribute), + typeof (ExportImageSourceHandlerAttribute) + }); + + MessagingCenter.Subscribe<Page, bool> (Device.PlatformServices, Page.BusySetSignalName, OnPageBusy); + + HardwareButtons.BackPressed += OnBackPressed; + + s_isInitialized = true; + s_state = launchActivatedEventArgs.PreviousExecutionState; + } + + static void OnBackPressed (object sender, BackPressedEventArgs e) + { + Application app = Application.Current; + if (app == null) + return; + + Page page = app.MainPage; + if (page == null) + return; + + var platform = page.Platform as Platform.WinRT.Platform; + if (platform == null) + return; + + e.Handled = platform.BackButtonPressed (); + } + + static ApplicationExecutionState s_state; + static bool s_isInitialized; + + const string LogFormat = "[{0}] {1}"; + + static async void OnPageBusy (Page sender, bool enabled) + { + StatusBar status = StatusBar.GetForCurrentView (); + if (enabled) { + status.ProgressIndicator.ProgressValue = null; + await status.ProgressIndicator.ShowAsync (); + } else + await status.ProgressIndicator.HideAsync (); + } + + static Windows.UI.Xaml.ResourceDictionary GetPhoneResources () + { + return new Windows.UI.Xaml.ResourceDictionary { + Source = new Uri ("ms-appx:///Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xbf") + }; + } + + static Windows.UI.Xaml.ResourceDictionary GetResources (UserControl control) + { + var gresources = control.Resources.MergedDictionaries[0]; + control.Resources.MergedDictionaries.Remove (gresources); + + return gresources; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs new file mode 100644 index 00000000..d829b787 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/FormsPivot.cs @@ -0,0 +1,65 @@ +using System.Threading.Tasks; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; + +#if WINDOWS_UWP + +namespace Xamarin.Forms.Platform.UWP +#else +namespace Xamarin.Forms.Platform.WinRT +#endif +{ + public class FormsPivot : Pivot, IToolbarProvider + { + public static readonly DependencyProperty ToolbarVisibilityProperty = DependencyProperty.Register("ToolbarVisibility", typeof(Visibility), typeof(FormsPivot), + new PropertyMetadata(Visibility.Collapsed)); + + public static readonly DependencyProperty ToolbarForegroundProperty = DependencyProperty.Register("ToolbarForeground", typeof(Brush), typeof(FormsPivot), new PropertyMetadata(default(Brush))); + + public static readonly DependencyProperty ToolbarBackgroundProperty = DependencyProperty.Register("ToolbarBackground", typeof(Brush), typeof(FormsPivot), new PropertyMetadata(default(Brush))); + + CommandBar _commandBar; + + TaskCompletionSource<CommandBar> _commandBarTcs; + + public Brush ToolbarBackground + { + get { return (Brush)GetValue(ToolbarBackgroundProperty); } + set { SetValue(ToolbarBackgroundProperty, value); } + } + + public Brush ToolbarForeground + { + get { return (Brush)GetValue(ToolbarForegroundProperty); } + set { SetValue(ToolbarForegroundProperty, value); } + } + + public Visibility ToolbarVisibility + { + get { return (Visibility)GetValue(ToolbarVisibilityProperty); } + set { SetValue(ToolbarVisibilityProperty, value); } + } + + Task<CommandBar> IToolbarProvider.GetCommandBarAsync() + { + if (_commandBar != null) + return Task.FromResult(_commandBar); + + _commandBarTcs = new TaskCompletionSource<CommandBar>(); + ApplyTemplate(); + return _commandBarTcs.Task; + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _commandBar = GetTemplateChild("CommandBar") as CommandBar; + TaskCompletionSource<CommandBar> tcs = _commandBarTcs; + if (tcs != null) + { + tcs.SetResult(_commandBar); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml new file mode 100644 index 00000000..521a9059 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/FormsTextBoxStyle.xaml @@ -0,0 +1,121 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:forms="using:Xamarin.Forms.Platform.WinRT" + xmlns:system="using:System"> + + <forms:TextAlignmentToHorizontalAlignmentConverter x:Key="AlignmentConverter" /> + + <Style x:Key="FormsTextBoxStyle" TargetType="forms:FormsTextBox"> + <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}"/> + <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}"/> + <Setter Property="Foreground" Value="{ThemeResource TextBoxForegroundThemeBrush}"/> + <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}"/> + <Setter Property="Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/> + <Setter Property="BackgroundFocusBrush" Value="{ThemeResource TextBoxFocusedBackgroundThemeBrush}"/> + <Setter Property="BorderBrush" Value="{ThemeResource TextBoxBorderThemeBrush}"/> + <Setter Property="BorderThickness" Value="0"/> + <Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}"/> + <Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}"/> + <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource TextBoxPlaceholderTextThemeBrush}" /> + <Setter Property="TextWrapping" Value="NoWrap"/> + <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto"/> + <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto"/> + <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/> + <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/> + <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/> + <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/> + <Setter Property="Margin" Value="0"/> + <Setter Property="VerticalAlignment" Value="Top"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="forms:FormsTextBox"> + <Grid Background="Transparent"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BorderElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledHeaderForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Normal"> + <Storyboard> + <DoubleAnimation Duration="0" To="{ThemeResource TextControlBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/> + </Storyboard> + </VisualState> + <VisualState x:Name="Focused"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextContentPresenter"/> + <!-- The commented-out section below *should* work, at least according to the docs and examples; but + instead it just crashes the application as soon as you focus a textbox. So the forms textbox class handles this + state manually in the phone version. I'm leaving this here in case someone can figure it out, because the VSM + is a much more elegant solution. (e.g., see the UWP project, where this *does* work) --> + <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BorderElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BackgroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}"/> + </ObjectAnimationUsingKeyFrames>--> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Border x:Name="BorderElement" + BorderBrush="{TemplateBinding BorderBrush}" + Background="{TemplateBinding Background}" + BorderThickness="{TemplateBinding BorderThickness}" + Grid.Row="1"/> + <ContentPresenter x:Name="HeaderContentPresenter" + ContentTemplate="{TemplateBinding HeaderTemplate}" + Content="{TemplateBinding Header}" + Margin="{ThemeResource TextControlHeaderMarginThemeThickness}" + Grid.Row="0" Style="{StaticResource HeaderContentPresenterStyle}"/> + <ScrollViewer x:Name="ContentElement" + AutomationProperties.AccessibilityView="Raw" + HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" + HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" + IsTabStop="False" + IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" + IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" + IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" + Margin="{TemplateBinding BorderThickness}" + MinHeight="{ThemeResource TextControlThemeMinHeight}" + Padding="{TemplateBinding Padding}" + Grid.Row="1" + FontSize="{ThemeResource ContentControlFontSize}" + VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" + VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" + ZoomMode="Disabled"/> + <ContentControl x:Name="PlaceholderTextContentPresenter" + Content="{TemplateBinding PlaceholderText}" + Foreground="{TemplateBinding PlaceholderForegroundBrush}" + FontSize="{ThemeResource ContentControlFontSize}" + IsTabStop="False" + Margin="{ThemeResource RichEditBoxTextThemeMargin}" + Padding="{TemplateBinding Padding}" + Grid.Row="1" + HorizontalAlignment="{Binding TextAlignment, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource AlignmentConverter}}"/> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml b/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml new file mode 100644 index 00000000..61f6667e --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/PhoneResources.xaml @@ -0,0 +1,694 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:Xamarin.Forms.Platform.WinRT"> + + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="Resources.xaml" /> + <ResourceDictionary Source="FormsTextBoxStyle.xaml" /> + </ResourceDictionary.MergedDictionaries> + + <!-- Fixes button sizing, including background outside the border --> + <Thickness x:Key="PhoneTouchTargetOverhang">0</Thickness> + <Style TargetType="Button"> + <Setter Property="MinHeight" Value="38.5" /> + </Style> + + <Style TargetType="local:FormsButton"> + <Setter Property="MinHeight" Value="38.5" /> + </Style> + + <Style TargetType="ToggleSwitch"> + <Setter Property="Foreground" Value="{ThemeResource ToggleSwitchForegroundThemeBrush}"/> + <Setter Property="HorizontalAlignment" Value="Stretch"/> + <Setter Property="VerticalAlignment" Value="Center"/> + <Setter Property="HorizontalContentAlignment" Value="Left"/> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> + <Setter Property="FontWeight" Value="SemiBold"/> + <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> + <Setter Property="Margin" Value="0"/> + <Setter Property="Padding" Value="0,0,25.5,0"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="ToggleSwitch"> + <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="PointerOver"/> + <VisualState x:Name="Pressed"/> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="OffContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="OnContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchKnob"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchThumbDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="SwitchKnob"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchThumbDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="OuterBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchOuterBorderDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchCurtain"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ToggleSwitchCurtainDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="ToggleStates"> + <VisualStateGroup.Transitions> + <VisualTransition x:Name="DraggingToOnTransition" From="Dragging" GeneratedDuration="0" To="On"> + <Storyboard> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.KnobCurrentToOnOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchKnob"/> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.CurtainCurrentToOnOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchCurtain"/> + </Storyboard> + </VisualTransition> + <VisualTransition x:Name="DraggingToOffTransition" From="Dragging" GeneratedDuration="0" To="Off"> + <Storyboard> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.KnobCurrentToOffOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchKnob"/> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.CurtainCurrentToOffOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchCurtain"/> + </Storyboard> + </VisualTransition> + <VisualTransition x:Name="OnToOffTransition" From="On" GeneratedDuration="0" To="Off"> + <Storyboard> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.KnobOnToOffOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchKnob"/> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.CurtainOnToOffOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchCurtain"/> + </Storyboard> + </VisualTransition> + <VisualTransition x:Name="OffToOnTransition" From="Off" GeneratedDuration="0" To="On"> + <Storyboard> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.KnobOffToOnOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchKnob"/> + <RepositionThemeAnimation FromHorizontalOffset="{Binding TemplateSettings.CurtainOffToOnOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" Storyboard.TargetName="SwitchCurtain"/> + </Storyboard> + </VisualTransition> + </VisualStateGroup.Transitions> + <VisualState x:Name="Dragging"/> + <VisualState x:Name="Off"> + <Storyboard> + <DoubleAnimation Duration="0" To="-64" Storyboard.TargetProperty="X" Storyboard.TargetName="CurtainTranslateTransform"/> + </Storyboard> + </VisualState> + <VisualState x:Name="On"> + <Storyboard> + <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="CurtainTranslateTransform"/> + <DoubleAnimation Duration="0" To="56.5" Storyboard.TargetProperty="X" Storyboard.TargetName="KnobTranslateTransform"/> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="ContentStates"> + <VisualState x:Name="OffContent"> + <Storyboard> + <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="OffContentPresenter"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="OffContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="OnContent"> + <Storyboard> + <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="OnContentPresenter"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="OnContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Grid Background="Transparent"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + <ColumnDefinition Width="13.5"/> + <ColumnDefinition Width="77"/> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="Auto"/> + <RowDefinition Height="9.5"/> + </Grid.RowDefinitions> + <ContentPresenter x:Name="HeaderContentPresenter" AutomationProperties.AccessibilityView="Raw" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{ThemeResource ToggleSwitchHeaderForegroundThemeBrush}" Margin="{TemplateBinding Padding}" Style="{StaticResource HeaderContentPresenterStyle}"/> + <Grid Margin="{TemplateBinding Padding}" Grid.Row="1"> + <ContentPresenter x:Name="OffContentPresenter" AutomationProperties.AccessibilityView="Raw" ContentTemplate="{TemplateBinding OffContentTemplate}" Content="{TemplateBinding OffContent}" FontWeight="Normal" FontSize="{ThemeResource TextStyleExtraLargeFontSize}" FontFamily="{ThemeResource PhoneFontFamilyNormal}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Opacity="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> + <ContentPresenter x:Name="OnContentPresenter" AutomationProperties.AccessibilityView="Raw" ContentTemplate="{TemplateBinding OnContentTemplate}" Content="{TemplateBinding OnContent}" FontWeight="Normal" FontSize="{ThemeResource TextStyleExtraLargeFontSize}" FontFamily="{ThemeResource PhoneFontFamilyNormal}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Opacity="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> + </Grid> + <Grid Grid.Column="2" ManipulationMode="None" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Bottom"> + <Grid x:Name="SwitchKnobBounds" Height="36"> + <Border x:Name="OuterBorder" BorderBrush="{ThemeResource ToggleSwitchOuterBorderBorderThemeBrush}" BorderThickness="2.5" Margin="3,4.5,3,4.5"> + <Border x:Name="InnerBorder" BorderBrush="{ThemeResource ToggleSwitchTrackBorderThemeBrush}" BorderThickness="2.5"> + <ContentPresenter x:Name="SwitchCurtainBounds"> + <ContentPresenter x:Name="SwitchCurtainClip"> + <Rectangle x:Name="SwitchCurtain" Fill="{ThemeResource ToggleSwitchCurtainBackgroundThemeBrush}" Width="64"> + <Rectangle.RenderTransform> + <TranslateTransform x:Name="CurtainTranslateTransform" X="-64"/> + </Rectangle.RenderTransform> + </Rectangle> + </ContentPresenter> + </ContentPresenter> + </Border> + </Border> + <Rectangle x:Name="SwitchKnob" Fill="{ThemeResource ToggleSwitchThumbBackgroundThemeBrush}" HorizontalAlignment="Left" Stroke="{ThemeResource ToggleSwitchThumbBorderThemeBrush}" StrokeThickness="2.5" Width="20.5"> + <Rectangle.RenderTransform> + <TranslateTransform x:Name="KnobTranslateTransform"/> + </Rectangle.RenderTransform> + </Rectangle> + </Grid> + <Thumb x:Name="SwitchThumb" AutomationProperties.AccessibilityView="Raw" Margin="-13.5,-15.5,-13.5,-6.5"> + <Thumb.Template> + <ControlTemplate TargetType="Thumb"> + <Rectangle Fill="Transparent"/> + </ControlTemplate> + </Thumb.Template> + </Thumb> + </Grid> + </Grid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style x:Key="FormsListViewItem" TargetType="ListViewItem"> + <Setter Property="HorizontalContentAlignment" Value="Stretch" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="ListViewItem"> + <Border x:Name="OuterContainer" RenderTransformOrigin="0.5,0.5"> + <Border.RenderTransform> + <ScaleTransform x:Name="ContentScaleTransform"/> + </Border.RenderTransform> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualStateGroup.Transitions> + <VisualTransition From="Pressed" To="Normal"> + <Storyboard> + <PointerUpThemeAnimation Storyboard.TargetName="TiltContainer"/> + </Storyboard> + </VisualTransition> + </VisualStateGroup.Transitions> + <VisualState x:Name="Normal"/> + <VisualState x:Name="Pressed"> + <Storyboard> + <PointerDownThemeAnimation Storyboard.TargetName="TiltContainer"/> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <DoubleAnimation Duration="0" To="{ThemeResource ListViewItemDisabledThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/> + <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Stroke" Storyboard.TargetName="NormalRectangle"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="CheckGlyph"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CheckBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="SelectedBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="SelectedEarmark"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Fill" Storyboard.TargetName="SelectedGlyph"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Grid x:Name="ReorderHintContent" Background="Transparent"> + <Border x:Name="ContentContainer"> + <Border x:Name="TiltContainer"> + <Border x:Name="ContentBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> + <Border.RenderTransform> + <TranslateTransform x:Name="ContentBorderTranslateTransform"/> + </Border.RenderTransform> + <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> + </Border> + </Border> + </Border> + </Grid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style x:Key="TabbedPageStyle" TargetType="local:FormsPivot"> + <Setter Property="HeaderTemplate"> + <Setter.Value> + <DataTemplate> + <TextBlock Text="{Binding Title}" /> + </DataTemplate> + </Setter.Value> + </Setter> + + <Setter Property="ItemTemplate" Value="{ThemeResource ContainedPageTemplate}" /> + + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="local:FormsPivot"> + <Grid x:Name="RootElement" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="Orientation"> + <VisualState x:Name="Portrait"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="grdToolbar"> + <DiscreteObjectKeyFrame KeyTime="0" Value="0,25,0,0"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + + </VisualState> + <VisualState x:Name="Landscape"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="grdToolbar"> + <DiscreteObjectKeyFrame KeyTime="0" Value="0,19,0,0"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Grid x:Name="grdToolbar" Background="{TemplateBinding ToolbarBackground}" > + <TextBlock Padding="10,0,0,0" Text="{TemplateBinding Title}" VerticalAlignment="Center" Style="{ThemeResource HeaderTextBlockStyle}" Foreground="{TemplateBinding ToolbarForeground}" Visibility="{TemplateBinding ToolbarVisibility}" Height="79"/> + </Grid> + <ScrollViewer x:Name="ScrollViewer" HorizontalSnapPointsAlignment="Center" HorizontalSnapPointsType="MandatorySingle" HorizontalScrollBarVisibility="Hidden" Margin="{TemplateBinding Padding}" Grid.Row="1" Template="{StaticResource ScrollViewerScrollBarlessTemplate}" VerticalSnapPointsType="None" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled" VerticalContentAlignment="Stretch" ZoomMode="Disabled"> + <PivotPanel x:Name="Panel" VerticalAlignment="Stretch"> + <PivotHeaderPanel x:Name="Header"> + <PivotHeaderPanel.RenderTransform> + <CompositeTransform x:Name="HeaderTranslateTransform" TranslateX="0"/> + </PivotHeaderPanel.RenderTransform> + </PivotHeaderPanel> + <ItemsPresenter x:Name="PivotItemPresenter"> + <ItemsPresenter.RenderTransform> + <TranslateTransform x:Name="ItemsPresenterTranslateTransform" X="0"/> + </ItemsPresenter.RenderTransform> + </ItemsPresenter> + </PivotPanel> + </ScrollViewer> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <DataTemplate x:Key="TextCell"> + <StackPanel Margin="5,0,0,0" Height="{Binding RenderHeight, Converter={StaticResource HeightConverter}}"> + <TextBlock + Text="{Binding Text}" + Style="{ThemeResource ListViewItemTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding TextColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" + local:ListViewRenderer.HighlightWhenSelected="true"/> + + <TextBlock + Text="{Binding Detail}" + Style="{ThemeResource ListViewItemContentTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding DetailColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" + local:ListViewRenderer.HighlightWhenSelected="true"/> + </StackPanel> + </DataTemplate> + + <DataTemplate x:Key="ListViewHeaderTextCell"> + <Border Margin="5,0,0,0" Background="{ThemeResource SystemColorControlAccentBrush}" Height="{Binding RenderHeight, Converter={StaticResource HeightConverter}}" MinHeight="{Binding RenderHeight, Converter={StaticResource HeightConverter}, ConverterParameter=60}" MinWidth="60" Padding="6"> + <StackPanel VerticalAlignment="Bottom"> + <TextBlock + Text="{Binding Text}" + Style="{ThemeResource GroupHeaderTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding TextColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" /> + + <TextBlock + Text="{Binding Detail}" + Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding DetailColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" /> + </StackPanel> + </Border> + </DataTemplate> + + <DataTemplate x:Key="ImageCell"> + <Grid Margin="5,0,0,0" Height="{Binding RenderHeight, Converter={StaticResource HeightConverter}}"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition /> + </Grid.ColumnDefinitions> + + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + + <Image Grid.Column="0" Grid.RowSpan="2" + DataContext="{Binding ImageSource, Converter={StaticResource ImageConverter}}" + Source="{Binding Value}" + VerticalAlignment="Center" /> + + <TextBlock Grid.Column="1" Grid.Row="0" + Text="{Binding Text}" + Style="{ThemeResource ListViewItemContentTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding TextColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" + local:ListViewRenderer.HighlightWhenSelected="true"/> + + <TextBlock Grid.Column="1" Grid.Row="1" + Text="{Binding Detail}" + Style="{ThemeResource ListViewItemContentTextBlockStyle}" + Visibility="{Binding Text,RelativeSource={RelativeSource Self}, Converter={StaticResource CollapseWhenEmpty}}" + Foreground="{Binding DetailColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" + local:ListViewRenderer.HighlightWhenSelected="true"/> + </Grid> + </DataTemplate> + + <DataTemplate x:Key="SwitchCell"> + <Grid Margin="5,0,0,0" Height="{Binding RenderHeight, Converter={StaticResource HeightConverter}}" HorizontalAlignment="Stretch"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + + <TextBlock + Grid.Column="0" Text="{Binding Text}" VerticalAlignment="Center" + local:ListViewRenderer.HighlightWhenSelected="true"/> + + <ToggleSwitch Grid.Column="1" IsOn="{Binding On, Mode=TwoWay}" OnContent="" OffContent="" VerticalAlignment="Center" /> + </Grid> + </DataTemplate> + + <DataTemplate x:Key="EntryCell"> + <local:EntryCellTextBox Margin="5,0,0,0" IsEnabled="{Binding IsEnabled}" Header="{Binding}" Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PlaceholderText="{Binding Placeholder}" TextAlignment="{Binding HorizontalTextAlignment,Converter={StaticResource HorizontalTextAlignmentConverter}}" InputScope="{Binding Keyboard,Converter={StaticResource KeyboardConverter}}" HorizontalAlignment="Stretch"> + <local:EntryCellTextBox.HeaderTemplate> + <DataTemplate> + <TextBlock + Text="{Binding Label}" + Style="{ThemeResource ListViewItemTextBlockStyle}" + Foreground="{Binding LabelColor, Converter={StaticResource ColorConverter}, ConverterParameter=DefaultTextForegroundThemeBrush}" + local:ListViewRenderer.HighlightWhenSelected="true"/> + </DataTemplate> + </local:EntryCellTextBox.HeaderTemplate> + </local:EntryCellTextBox> + </DataTemplate> + + <ControlTemplate x:Key="MasterDetailPopup"> + <Grid Background="{TemplateBinding Background}"> + <Grid.Resources> + <Style TargetType="local:PageControl" BasedOn="{StaticResource PageControlDefaultStyle}"> + <Setter Property="Background" Value="Transparent" /> + </Style> + </Grid.Resources> + + <Popup x:Name="popup" IsLightDismissEnabled="true"> + <Popup.ChildTransitions> + <TransitionCollection> + <PopupThemeTransition /> + </TransitionCollection> + </Popup.ChildTransitions> + + <Border Margin="0" Padding="0" BorderThickness="0" Background="{Binding Converter={StaticResource MasterBackgroundConverter}, RelativeSource={RelativeSource Mode=TemplatedParent}}"> + <ContentPresenter x:Name="masterPresenter" /> + </Border> + </Popup> + + <ContentPresenter x:Name="detailPresenter" /> + </Grid> + </ControlTemplate> + + <Style x:Key="PageControlDefaultStyle" TargetType="local:PageControl"> + <Setter Property="TitleBrush" Value="{ThemeResource DefaultTextForegroundThemeBrush}" /> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="local:PageControl"> + <Grid Background="{TemplateBinding Background}"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="*" /> + </Grid.RowDefinitions> + + <Grid Height="79" Background="{TemplateBinding NavigationBarBackground}" Visibility="{Binding ShowNavigationBar,RelativeSource={RelativeSource Mode=TemplatedParent},Converter={StaticResource BoolVisibilityConverter}}"> + <TextBlock Margin="10,0,0,0" Name="title" Foreground="{TemplateBinding TitleBrush}" VerticalAlignment="Center" Style="{ThemeResource HeaderTextBlockStyle}" Text="{Binding Title}" /> + </Grid> + <ContentPresenter x:Name="presenter" Grid.Row="1" ContentTransitions="{TemplateBinding ContentTransitions}" /> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + + <Style TargetType="local:PageControl" BasedOn="{StaticResource PageControlDefaultStyle}" /> + + <DataTemplate x:Key="TabbedPage"> + <local:TabbedPagePresenter Content="{Binding Converter={StaticResource PageToRenderer}}" /> + </DataTemplate> + + <DataTemplate x:Key="TabbedPageHeader"> + <TextBlock Text="{Binding Title}" /> + </DataTemplate> + + <Style x:Key="JumpListGrid" TargetType="GridView"> + <Setter Property="Background" Value="#80000000" /> + <Setter Property="ItemTemplate"> + <Setter.Value> + <DataTemplate> + <Border Background="{ThemeResource SystemColorControlAccentBrush}" Padding="5" Margin="3" MinHeight="80" MinWidth="80"> + <TextBlock Text="{Binding}" Style="{ThemeResource SubheaderTextBlockStyle}" VerticalAlignment="Bottom" /> + </Border> + </DataTemplate> + </Setter.Value> + </Setter> + </Style> + + <GroupStyle x:Key="ListViewGroup" HidesIfEmpty="False"> + <GroupStyle.HeaderTemplate> + <DataTemplate> + <local:CellControl IsGroupHeader="true" HorizontalContentAlignment="Stretch" /> + </DataTemplate> + </GroupStyle.HeaderTemplate> + </GroupStyle> + + <Style TargetType="local:FormsTextBox"> + <Setter Property="Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}" /> + <Setter Property="Foreground" Value="{ThemeResource TextBoxForegroundThemeBrush}" /> + <Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}" /> + </Style> + + <Style TargetType="local:FormsComboBox"> + <Setter Property="Foreground" Value="{ThemeResource ComboBoxForegroundThemeBrush}"/> + <Setter Property="Background" Value="{ThemeResource ComboBoxBackgroundThemeBrush}"/> + <Setter Property="BorderBrush" Value="{ThemeResource ComboBoxBorderThemeBrush}"/> + <Setter Property="BorderThickness" Value="{ThemeResource ComboBoxBorderThemeThickness}"/> + <Setter Property="HorizontalContentAlignment" Value="Left"/> + <Setter Property="FontFamily" Value="{ThemeResource PhoneFontFamilyNormal}"/> + <Setter Property="FontSize" Value="{ThemeResource ContentControlFontSize}"/> + <Setter Property="Margin" Value="0"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="local:FormsComboBox"> + <Grid x:Name="ComboBoxGrid"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="Auto"/> + </Grid.RowDefinitions> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualStateGroup.Transitions> + <VisualTransition From="Pressed" To="PointerOver"> + <Storyboard> + <PointerUpThemeAnimation Storyboard.TargetName="Background"/> + </Storyboard> + </VisualTransition> + <VisualTransition From="PointerOver" To="Normal"> + <Storyboard> + <PointerUpThemeAnimation Storyboard.TargetName="Background"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextBlock"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource PhoneMidBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextBlock"> + <DiscreteObjectKeyFrame KeyTime="0" Value="1"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualTransition> + <VisualTransition From="Pressed" To="Normal"> + <Storyboard> + <PointerUpThemeAnimation Storyboard.TargetName="Background"/> + </Storyboard> + </VisualTransition> + </VisualStateGroup.Transitions> + <VisualState x:Name="Normal"> + <Storyboard> + <DoubleAnimation Duration="0" To="{ThemeResource ComboBoxFlyoutListPlaceholderTextOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextBlock"/> + </Storyboard> + </VisualState> + <VisualState x:Name="PointerOver"/> + <VisualState x:Name="Pressed"> + <Storyboard> + <PointerDownThemeAnimation Storyboard.TargetName="Background"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="UserControl"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxPressedForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Highlighted"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxHighlightedBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxHighlightedBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="UserControl"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxHighlightedForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="FlyoutButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="UserControl"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextBlock"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextBlock"/> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="DropDownStates"> + <VisualState x:Name="Opened"> + <Storyboard> + <DoubleAnimation Duration="0:0:0.25" EnableDependentAnimation="True" + From="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" + To="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" + Storyboard.TargetProperty="Height" Storyboard.TargetName="ItemsPresenterHost"> + <DoubleAnimation.EasingFunction> + <ExponentialEase EasingMode="EaseInOut" Exponent="6"/> + </DoubleAnimation.EasingFunction> + </DoubleAnimation> + <DoubleAnimation Duration="0:0:0.25" To="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" + Storyboard.TargetProperty="Y" + Storyboard.TargetName="ItemsPresenterTranslateTransform"> + <DoubleAnimation.EasingFunction> + <ExponentialEase EasingMode="EaseInOut" Exponent="6"/> + </DoubleAnimation.EasingFunction> + </DoubleAnimation> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="UserControl"> + <DiscreteObjectKeyFrame KeyTime="0" Value="True"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxHighlightedBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="UserControl"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ComboBoxHighlightedForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Closed"> + <Storyboard> + <!-- Dummy zero-duration animation so we can hook into the closing animation --> + <DoubleAnimation Duration="0:0:0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ItemsPresenterHost" /> + <DoubleAnimation Duration="0:0:0.2" EnableDependentAnimation="True" + From="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" + To="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" + Storyboard.TargetProperty="Height" Storyboard.TargetName="ItemsPresenterHost"> + <DoubleAnimation.EasingFunction> + <ExponentialEase EasingMode="EaseInOut" Exponent="6"/> + </DoubleAnimation.EasingFunction> + </DoubleAnimation> + <DoubleAnimation Duration="0:0:0.2" + To="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" + Storyboard.TargetProperty="Y" Storyboard.TargetName="ItemsPresenterTranslateTransform"> + <DoubleAnimation.EasingFunction> + <ExponentialEase EasingMode="EaseInOut" Exponent="6"/> + </DoubleAnimation.EasingFunction> + </DoubleAnimation> + </Storyboard> + </VisualState> + </VisualStateGroup> + <VisualStateGroup x:Name="PresenterStates"> + <VisualState x:Name="Full"/> + <VisualState x:Name="InlineNormal"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FlyoutButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ShortListOuterBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="InlinePlaceholder"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FlyoutButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ShortListOuterBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> + </ObjectAnimationUsingKeyFrames> + <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PlaceholderTextContentPresenter"/> + <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ItemsPresenter"/> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <ContentPresenter x:Name="HeaderContentPresenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" FlowDirection="{TemplateBinding FlowDirection}" HorizontalAlignment="Left" Margin="0,0,0,-4.5" Style="{StaticResource HeaderContentPresenterStyle}" Visibility="Collapsed"/> + <Button x:Name="FlyoutButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" FontWeight="Normal" FlowDirection="{TemplateBinding FlowDirection}" FontSize="{ThemeResource ContentControlFontSize}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" MinHeight="{ThemeResource ComboBoxItemMinHeightThemeSize}" Padding="6.5,0,0,0" Grid.Row="1"> + <ContentPresenter x:Name="ContentPresenter" Margin="0,0.8,0,0" MinHeight="32.5"> + <TextBlock x:Name="PlaceholderTextBlock" Margin="0" Style="{StaticResource ComboBoxPlaceholderTextBlockStyle}" Text="{TemplateBinding PlaceholderText}"/> + </ContentPresenter> + </Button> + <Border x:Name="ShortListOuterBorder" Margin="{ThemeResource PhoneTouchTargetOverhang}" Grid.Row="1" Visibility="Collapsed"> + <Border x:Name="Background" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> + <UserControl x:Name="UserControl" Foreground="{TemplateBinding Foreground}" FlowDirection="{TemplateBinding FlowDirection}" IsHitTestVisible="False"> + <Canvas x:Name="ItemsPresenterHost" HorizontalAlignment="Left" MinHeight="{ThemeResource ComboBoxItemMinHeightThemeSize}"> + <ContentPresenter x:Name="PlaceholderTextContentPresenter" Content="{TemplateBinding PlaceholderText}" Margin="{ThemeResource ComboBoxPlaceholderTextThemeMargin}" Opacity="0" Style="{StaticResource PlaceholderContentPresenterStyle}"/> + <ItemsPresenter x:Name="ItemsPresenter" Margin="0,0.8,0,0"> + <ItemsPresenter.RenderTransform> + <TranslateTransform x:Name="ItemsPresenterTranslateTransform"/> + </ItemsPresenter.RenderTransform> + </ItemsPresenter> + </Canvas> + </UserControl> + </Border> + </Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/Properties/AssemblyInfo.cs b/Xamarin.Forms.Platform.WinRT.Phone/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..6f33e0c7 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/Properties/AssemblyInfo.cs @@ -0,0 +1,14 @@ +using System.Reflection; +using Xamarin.Forms; +using Xamarin.Forms.Platform.WinRT; + +[assembly: AssemblyTitle("Xamarin.Forms.Platform.WinRT.Phone")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCulture("")] + +[assembly: Dependency (typeof (WindowsPhoneResourcesProvider))] + +[assembly: ExportRenderer (typeof (SearchBar), typeof (SearchBarRenderer))] + +[assembly: ExportRenderer (typeof (TabbedPage), typeof (TabbedPageRenderer))]
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/SearchBarRenderer.cs b/Xamarin.Forms.Platform.WinRT.Phone/SearchBarRenderer.cs new file mode 100644 index 00000000..33bd782f --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/SearchBarRenderer.cs @@ -0,0 +1,160 @@ +using System; +using System.ComponentModel; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; + +namespace Xamarin.Forms.Platform.WinRT +{ + public class SearchBarRenderer + : ViewRenderer<SearchBar, SearchBox> + { + protected override void OnElementChanged (ElementChangedEventArgs<SearchBar> e) + { + if (e.NewElement != null) { + if (Control == null) { + SetNativeControl (new SearchBox ()); + Control.QuerySubmitted += OnQuerySubmitted; + Control.QueryChanged += OnQueryChanged; + Control.Loaded += (sender, args) => { + _queryTextBox = Control.GetFirstDescendant<FormsTextBox> (); + UpdateTextColor (); + UpdatePlaceholderColor (); + }; + } + + UpdateText (); + UpdatePlaceholder (); + UpdateFont (); + UpdateAlignment (); + UpdatePlaceholderColor (); + UpdateTextColor (); + } + + base.OnElementChanged (e); + } + + protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) + { + base.OnElementPropertyChanged (sender, e); + + if (e.PropertyName == SearchBar.TextProperty.PropertyName) + UpdateText (); + else if (e.PropertyName == SearchBar.PlaceholderProperty.PropertyName) + UpdatePlaceholder (); + else if (e.PropertyName == SearchBar.FontAttributesProperty.PropertyName) + UpdateFont (); + else if (e.PropertyName == SearchBar.FontFamilyProperty.PropertyName) + UpdateFont (); + else if (e.PropertyName == SearchBar.FontSizeProperty.PropertyName) + UpdateFont (); + else if (e.PropertyName == SearchBar.HorizontalTextAlignmentProperty.PropertyName) + UpdateAlignment (); + else if (e.PropertyName == SearchBar.PlaceholderColorProperty.PropertyName) + UpdatePlaceholderColor (); + else if (e.PropertyName == SearchBar.TextColorProperty.PropertyName) + UpdateTextColor (); + } + + bool _fontApplied; + + void OnQuerySubmitted (SearchBox sender, SearchBoxQuerySubmittedEventArgs e) + { + Element.OnSearchButtonPressed (); + } + + void UpdatePlaceholder () + { + Control.PlaceholderText = Element.Placeholder ?? string.Empty; + } + + void UpdateFont () + { + if (Control == null) + return; + + var searchBar = Element; + + if (searchBar == null) + return; + + bool searchBarIsDefault = searchBar.FontFamily == null && searchBar.FontSize == Device.GetNamedSize (NamedSize.Default, typeof (SearchBar), true) && searchBar.FontAttributes == FontAttributes.None; + + if (searchBarIsDefault && !_fontApplied) + return; + + if (searchBarIsDefault) { + Control.ClearValue (Windows.UI.Xaml.Controls.Control.FontStyleProperty); + Control.ClearValue (Windows.UI.Xaml.Controls.Control.FontSizeProperty); + Control.ClearValue (Windows.UI.Xaml.Controls.Control.FontFamilyProperty); + Control.ClearValue (Windows.UI.Xaml.Controls.Control.FontWeightProperty); + Control.ClearValue (Windows.UI.Xaml.Controls.Control.FontStretchProperty); + } else { + Control.ApplyFont (searchBar); + } + + _fontApplied = true; + } + + void OnQueryChanged (SearchBox sender, SearchBoxQueryChangedEventArgs e) + { + ((IElementController) Element).SetValueFromRenderer (SearchBar.TextProperty, e.QueryText); + } + + void UpdateText () + { + Control.QueryText = Element.Text ?? string.Empty; + } + + void UpdateAlignment () + { + Control.HorizontalTextAlignment = Element.HorizontalTextAlignment; + } + + void UpdateTextColor () + { + if (_queryTextBox == null) { + return; + } + + var textColor = Element.TextColor; + + if (textColor.IsDefault) + { + if (_defaultTextColorBrush == null) { + return; + } + + _queryTextBox.Foreground = _defaultTextColorBrush; + } + + _defaultTextColorBrush = _defaultTextColorBrush ?? _queryTextBox.Foreground; + + _queryTextBox.Foreground = textColor.ToBrush(); + } + + void UpdatePlaceholderColor () + { + if (_queryTextBox == null) { + return; + } + + var placeholderColor = Element.PlaceholderColor; + + if (placeholderColor.IsDefault) { + if (_defaultPlaceholderColorBrush == null) { + return; + } + + _queryTextBox.PlaceholderForegroundBrush = _defaultPlaceholderColorBrush; + } + + _defaultPlaceholderColorBrush = _defaultPlaceholderColorBrush ?? _queryTextBox.PlaceholderForegroundBrush; + + _queryTextBox.PlaceholderForegroundBrush = placeholderColor.ToBrush (); + } + + FormsTextBox _queryTextBox; + Brush _defaultTextColorBrush; + Brush _defaultPlaceholderColorBrush; + } +} diff --git a/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml b/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml new file mode 100644 index 00000000..3b609fe8 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml @@ -0,0 +1,248 @@ +<Control + x:Class="Xamarin.Forms.Platform.WinRT.SearchBox" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:winRt="using:Xamarin.Forms.Platform.WinRT" + mc:Ignorable="d" + d:DesignHeight="300" + d:DesignWidth="400"> + + <Control.Resources> + <ResourceDictionary> + <ResourceDictionary.ThemeDictionaries> + <ResourceDictionary x:Key="Default"> + <SolidColorBrush x:Key="SearchBoxBackgroundThemeBrush" Color="#CCFFFFFF" /> + <SolidColorBrush x:Key="SearchBoxBorderThemeBrush" Color="#FF2A2A2A" /> + <SolidColorBrush x:Key="SearchBoxDisabledBackgroundThemeBrush" Color="Transparent" /> + <SolidColorBrush x:Key="SearchBoxDisabledTextThemeBrush" Color="#66FFFFFF" /> + <SolidColorBrush x:Key="SearchBoxDisabledBorderThemeBrush" Color="#FF666666" /> + <SolidColorBrush x:Key="SearchBoxPointerOverBackgroundThemeBrush" Color="#DDFFFFFF" /> + <SolidColorBrush x:Key="SearchBoxPointerOverTextThemeBrush" Color="#99000000" /> + <SolidColorBrush x:Key="SearchBoxPointerOverBorderThemeBrush" Color="#FFDDDDDD" /> + <SolidColorBrush x:Key="SearchBoxFocusedBackgroundThemeBrush" Color="#FFFFFFFF" /> + <SolidColorBrush x:Key="SearchBoxFocusedTextThemeBrush" Color="#FF000000" /> + <SolidColorBrush x:Key="SearchBoxFocusedBorderThemeBrush" Color="#FF2A2A2A" /> + <SolidColorBrush x:Key="SearchBoxButtonBackgroundThemeBrush" Color="#FF4617B4" /> + <SolidColorBrush x:Key="SearchBoxButtonForegroundThemeBrush" Color="White" /> + <SolidColorBrush x:Key="SearchBoxButtonPointerOverForegroundThemeBrush" Color="White" /> + <SolidColorBrush x:Key="SearchBoxButtonPointerOverBackgroundThemeBrush" Color="#FF5F37BE" /> + <SolidColorBrush x:Key="SearchBoxSeparatorSuggestionForegroundThemeBrush" Color="Black" /> + <SolidColorBrush x:Key="SearchBoxHitHighlightForegroundThemeBrush" Color="#FF4617B4" /> + <SolidColorBrush x:Key="SearchBoxHitHighlightSelectedForegroundThemeBrush" Color="#FFA38BDA" /> + <SolidColorBrush x:Key="SearchBoxForegroundThemeBrush" Color="Black" /> + </ResourceDictionary> + </ResourceDictionary.ThemeDictionaries> + + <x:Double x:Key="SearchBoxTextBoxThemeMinHeight">28</x:Double> + <x:Double x:Key="SearchBoxContentThemeFontSize">15</x:Double> + <Thickness x:Key="SearchBoxThemePadding">8,4,8,4</Thickness> + <Thickness x:Key="SearchBoxBorderThemeThickness">2</Thickness> + <FontWeight x:Key="SearchBoxButtonThemeFontWeight">Normal</FontWeight> + <FontWeight x:Key="SearchBoxContentThemeFontWeight">Normal</FontWeight> + <winRt:TextAlignmentToHorizontalAlignmentConverter x:Key="AlignmentConverter" /> + </ResourceDictionary> + </Control.Resources> + + <Control.Style> + <Style TargetType="Control"> + <Setter Property="Background" Value="{ThemeResource SearchBoxBackgroundThemeBrush}"/> + <Setter Property="BorderBrush" Value="{ThemeResource SearchBoxBorderThemeBrush}"/> + <Setter Property="BorderThickness" Value="{ThemeResource SearchBoxBorderThemeThickness}"/> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> + <Setter Property="FontSize" Value="{ThemeResource SearchBoxContentThemeFontSize}"/> + <Setter Property="FontWeight" Value="{ThemeResource SearchBoxContentThemeFontWeight}"/> + <Setter Property="Foreground" Value="{ThemeResource SearchBoxForegroundThemeBrush}"/> + <Setter Property="Padding" Value="{ThemeResource SearchBoxThemePadding}"/> + <Setter Property="IsTabStop" Value="False"/> + <Setter Property="Typography.StylisticSet20" Value="True"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate> + <Grid x:Name="SearchBoxGrid"> + <Grid.Resources> + <Style x:Key="SearchButtonStyle" TargetType="Button"> + <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}"/> + <Setter Property="IsTabStop" Value="False"/> + <Setter Property="VerticalAlignment" Value="Stretch"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="Button"> + <Grid Background="Transparent"> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"/> + <VisualState x:Name="PointerOver"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="SearchGlyph"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxButtonPointerOverForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchButtonBackground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxButtonPointerOverBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Pressed"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="SearchGlyph"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxFocusedTextThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchButtonBackground"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxFocusedBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"/> + </VisualStateGroup> + <VisualStateGroup x:Name="FocusStates"> + <VisualState x:Name="Focused"/> + <VisualState x:Name="Unfocused"/> + <VisualState x:Name="PointerFocused"/> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + <Grid x:Name="SearchButtonBackground" Background="{TemplateBinding Background}"> + <SymbolIcon x:Name="SearchGlyph" Symbol="Find" AutomationProperties.AccessibilityView="Raw" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center"/> + </Grid> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + <Style x:Key="SearchTextBoxStyle" TargetType="winRt:FormsTextBox"> + <Setter Property="Margin" Value="0" /> + <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}"/> + <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}"/> + <Setter Property="Foreground" Value="{ThemeResource TextBoxForegroundThemeBrush}"/> + <Setter Property="Background" Value="{ThemeResource TextBoxBackgroundThemeBrush}"/> + <Setter Property="BorderBrush" Value="{ThemeResource TextBoxBorderThemeBrush}"/> + <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource TextBoxPlaceholderTextThemeBrush}"/> + <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}"/> + <Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}"/> + <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> + <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> + <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/> + <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/> + <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/> + <Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="winRt:FormsTextBox"> + <Grid> + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="BackgroundElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="BorderElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentElement"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="PlaceholderTextContentPresenter"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Normal"> + <Storyboard> + <DoubleAnimation Duration="0" To="{ThemeResource TextControlBackgroundThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/> + <DoubleAnimation Duration="0" To="{ThemeResource TextControlBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/> + </Storyboard> + </VisualState> + <VisualState x:Name="PointerOver"> + <Storyboard> + <DoubleAnimation Duration="0" To="{ThemeResource TextControlPointerOverBackgroundThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundElement"/> + <DoubleAnimation Duration="0" To="{ThemeResource TextControlPointerOverBorderThemeOpacity}" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BorderElement"/> + </Storyboard> + </VisualState> + <VisualState x:Name="Focused"/> + </VisualStateGroup> + <VisualStateGroup x:Name="ButtonStates"/> + </VisualStateManager.VisualStateGroups> + + <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}" /> + <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" /> + <ScrollViewer x:Name="ContentElement" AutomationProperties.AccessibilityView="Raw" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsTabStop="False" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled"/> + <ContentControl x:Name="PlaceholderTextContentPresenter" Content="{TemplateBinding PlaceholderText}" Foreground="{TemplateBinding PlaceholderForegroundBrush}" IsHitTestVisible="False" IsTabStop="False" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" + HorizontalAlignment="{Binding TextAlignment, + RelativeSource={RelativeSource Mode=TemplatedParent}, + Converter={StaticResource AlignmentConverter}}" /> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Grid.Resources> + + <VisualStateManager.VisualStateGroups> + <VisualStateGroup x:Name="CommonStates"> + <VisualState x:Name="Normal"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchBoxGrid"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding Background, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="SearchBoxBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BorderBrush, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="SearchButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Disabled"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchBoxGrid"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxDisabledBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="SearchBoxBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxDisabledBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="SearchButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxDisabledTextThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchTextBox"> + <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + <VisualState x:Name="Focused"> + <Storyboard> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchBoxGrid"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxFocusedBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="SearchBoxBorder"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxFocusedBorderThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="SearchButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxButtonForegroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="SearchButton"> + <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SearchBoxButtonBackgroundThemeBrush}"/> + </ObjectAnimationUsingKeyFrames> + </Storyboard> + </VisualState> + </VisualStateGroup> + </VisualStateManager.VisualStateGroups> + + <Border x:Name="SearchBoxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition/> + <ColumnDefinition Width="Auto"/> + </Grid.ColumnDefinitions> + + <winRt:FormsTextBox x:Name="SearchTextBox" BorderThickness="0" Background="Transparent" Text="{Binding Path=QueryText, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" FontStyle="{TemplateBinding FontStyle}" InputScope="Search" MinHeight="{ThemeResource SearchBoxTextBoxThemeMinHeight}" MaxLength="2048" Padding="{TemplateBinding Padding}" Style="{StaticResource SearchTextBoxStyle}" TextWrapping="NoWrap" VerticalAlignment="Stretch"/> + <Button x:Name="SearchButton" AutomationProperties.AccessibilityView="Raw" Background="Transparent" Grid.Column="1" FontWeight="{ThemeResource SearchBoxButtonThemeFontWeight}" Style="{StaticResource SearchButtonStyle}"/> + </Grid> + </Border> + </Grid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + </Control.Style> +</Control>
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml.cs b/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml.cs new file mode 100644 index 00000000..4cc8ac1c --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/SearchBox.xaml.cs @@ -0,0 +1,157 @@ +using System; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace Xamarin.Forms.Platform.WinRT +{ + public class SearchBoxQuerySubmittedEventArgs + : EventArgs + { + } + + public class SearchBoxQueryChangedEventArgs + : EventArgs + { + public SearchBoxQueryChangedEventArgs (string query) + { + QueryText = query; + } + + public string QueryText + { + get; + private set; + } + } + + public delegate void QueryChangedEventHandler (SearchBox search, SearchBoxQueryChangedEventArgs args); + public delegate void QuerySubmittedEventHandler (SearchBox search, SearchBoxQuerySubmittedEventArgs args); + + public sealed partial class SearchBox + { + public SearchBox () + { + InitializeComponent (); + + IsEnabledChanged += OnIsEnabledChanged; + } + + public event QuerySubmittedEventHandler QuerySubmitted; + public event QueryChangedEventHandler QueryChanged; + + public static readonly DependencyProperty QueryTextProperty = DependencyProperty.Register ( + "QueryText", typeof(string), typeof(SearchBox), new PropertyMetadata (null, OnQueryTextChanged)); + + public string QueryText + { + get { return (string)GetValue (QueryTextProperty); } + set { SetValue (QueryTextProperty, value); } + } + + public static readonly DependencyProperty PlaceholderTextProperty = DependencyProperty.Register ( + "PlaceholderText", typeof(string), typeof(SearchBox), new PropertyMetadata (null, OnPlaceholderChanged)); + + public string PlaceholderText + { + get { return (string)GetValue (PlaceholderTextProperty); } + set { SetValue (PlaceholderTextProperty, value); } + } + + public static readonly DependencyProperty HorizontalTextAlignmentProperty = DependencyProperty.Register ( + "HorizontalTextAlignment", typeof(string), typeof(SearchBox), new PropertyMetadata (null, OnAlignmentChanged)); + + public TextAlignment HorizontalTextAlignment + { + get { return (TextAlignment)GetValue (HorizontalTextAlignmentProperty); } + set { SetValue (HorizontalTextAlignmentProperty, value); } + } + + protected override void OnApplyTemplate () + { + base.OnApplyTemplate (); + + GoToNormal (); + + _searchTextBox = (TextBox)GetTemplateChild ("SearchTextBox"); + + ((Windows.UI.Xaml.Controls.Button) GetTemplateChild ("SearchButton")).Click += OnSearchButtonClicked; + + UpdatePlaceholder (); + UpdateAlignment (); + } + + protected override void OnGotFocus (RoutedEventArgs e) + { + base.OnGotFocus (e); + + VisualStateManager.GoToState (this, "Focused", true); + } + + protected override void OnLostFocus (RoutedEventArgs e) + { + base.OnLostFocus (e); + + GoToNormal (); + } + + void OnSearchButtonClicked (object sender, RoutedEventArgs e) + { + var querySubmitted = QuerySubmitted; + if (querySubmitted != null) + querySubmitted (this, new SearchBoxQuerySubmittedEventArgs()); + } + + TextBox _searchTextBox; + + void GoToNormal () + { + VisualStateManager.GoToState (this, (IsEnabled) ? "Normal" : "Disabled", false); + } + + void UpdatePlaceholder () + { + if (_searchTextBox == null) + return; + + _searchTextBox.PlaceholderText = PlaceholderText; + } + + void OnIsEnabledChanged (object sender, DependencyPropertyChangedEventArgs e) + { + string state = "Normal"; + if (!(bool) e.NewValue) + state = "Disabled"; + else if (FocusState != FocusState.Unfocused) + state = "Focused"; + + VisualStateManager.GoToState (this, state, true); + } + + static void OnQueryTextChanged (DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var search = (SearchBox) d; + var changed = search.QueryChanged; + if (changed != null) + changed (search, new SearchBoxQueryChangedEventArgs ((string) e.NewValue)); + } + + static void OnPlaceholderChanged (DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((SearchBox) d).UpdatePlaceholder (); + } + + static void OnAlignmentChanged (DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((SearchBox) d).UpdateAlignment (); + } + + void UpdateAlignment () + { + if (_searchTextBox == null) { + return; + } + + _searchTextBox.TextAlignment = HorizontalTextAlignment.ToNativeTextAlignment(); + } + } +} diff --git a/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs new file mode 100644 index 00000000..9de3a623 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/TabbedPageRenderer.cs @@ -0,0 +1,284 @@ +using System; +using System.Collections.Specialized; +using System.ComponentModel; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Automation; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Media; + +namespace Xamarin.Forms.Platform.WinRT +{ + internal class TabbedPagePresenter : Windows.UI.Xaml.Controls.ContentPresenter + { + public TabbedPagePresenter () + { + SizeChanged += (s, e) => { + if (ActualWidth > 0 && ActualHeight > 0) { + var tab = ((Page) DataContext); + ((TabbedPage) tab.RealParent).ContainerArea = new Rectangle (0, 0, ActualWidth, ActualHeight); + } + }; + } + } + + public class TabbedPageRenderer + : IVisualElementRenderer, ITitleProvider + { + public event EventHandler<VisualElementChangedEventArgs> ElementChanged; + + public FrameworkElement ContainerElement + { + get { return Control; } + } + + VisualElement IVisualElementRenderer.Element + { + get { return Element; } + } + + public Pivot Control + { + get; + private set; + } + + public TabbedPage Element + { + get; + private set; + } + + public void SetElement (VisualElement element) + { + if (element != null && !(element is TabbedPage)) + throw new ArgumentException ("Element must be a TabbedPage", "element"); + + TabbedPage oldElement = Element; + Element = (TabbedPage) element; + + if (oldElement != null) { + oldElement.PropertyChanged -= OnElementPropertyChanged; + ((INotifyCollectionChanged) oldElement.Children).CollectionChanged -= OnPagesChanged; + } + + if (element != null) { + if (Control == null) { + Control = new FormsPivot { + Style = (Windows.UI.Xaml.Style) Windows.UI.Xaml.Application.Current.Resources["TabbedPageStyle"] + }; + Control.HeaderTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPageHeader"]; + Control.ItemTemplate = (Windows.UI.Xaml.DataTemplate)Windows.UI.Xaml.Application.Current.Resources["TabbedPage"]; + + Control.SelectionChanged += OnSelectionChanged; + + Tracker = new BackgroundTracker<Pivot> (Windows.UI.Xaml.Controls.Control.BackgroundProperty) { + Element = (Page) element, + Control = Control, + Container = Control + }; + + Control.Loaded += OnLoaded; + Control.Unloaded += OnUnloaded; + } + + Control.DataContext = Element; + OnPagesChanged (Element.Children, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset)); + UpdateCurrentPage (); + + ((INotifyCollectionChanged) Element.Children).CollectionChanged += OnPagesChanged; + element.PropertyChanged += OnElementPropertyChanged; + + if (!string.IsNullOrEmpty (element.AutomationId)) + Control.SetValue (AutomationProperties.AutomationIdProperty, element.AutomationId); + } + + OnElementChanged (new VisualElementChangedEventArgs (oldElement, element)); + } + + public SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint) + { + var constraint = new Windows.Foundation.Size (widthConstraint, heightConstraint); + + var oldWidth = Control.Width; + var oldHeight = Control.Height; + + Control.Height = double.NaN; + Control.Width = double.NaN; + + Control.Measure (constraint); + var result = new Size (Math.Ceiling (Control.DesiredSize.Width), Math.Ceiling (Control.DesiredSize.Height)); + + Control.Width = oldWidth; + Control.Height = oldHeight; + + return new SizeRequest (result); + } + + public void Dispose () + { + Dispose (true); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || _disposed) + return; + + _disposed = true; + SetElement (null); + Tracker = null; + } + + protected VisualElementTracker<Page, Pivot> Tracker + { + get + { + return _tracker; + } + set + { + if (_tracker == value) + return; + + if (_tracker != null) { + _tracker.Dispose (); + /*this.tracker.Updated -= OnTrackerUpdated;*/ + } + + _tracker = value; + + /*if (this.tracker != null) + this.tracker.Updated += OnTrackerUpdated;*/ + } + } + + bool ITitleProvider.ShowTitle + { + get + { + return _showTitle; + } + + set + { + if (_showTitle == value) + return; + _showTitle = value; + + (Control as FormsPivot).ToolbarVisibility = _showTitle ? Visibility.Visible : Visibility.Collapsed; + } + } + + string ITitleProvider.Title + { + get + { + return (string)Control?.Title; + } + + set + { + if (Control != null) + Control.Title = value; + } + } + + Brush ITitleProvider.BarBackgroundBrush + { + set + { + (Control as FormsPivot).ToolbarBackground = value; + } + } + + Brush ITitleProvider.BarForegroundBrush + { + set + { + (Control as FormsPivot).ToolbarForeground = value; + } + } + + protected virtual void OnElementChanged (VisualElementChangedEventArgs e) + { + var changed = ElementChanged; + if (changed != null) + changed (this, e); + } + + bool _disposed; + VisualElementTracker<Page, Pivot> _tracker; + bool _showTitle; + + void OnPagesChanged (object sender, NotifyCollectionChangedEventArgs e) + { + e.Apply (Element.Children, Control.Items); + + // Potential performance issue, UpdateLayout () is called for every page change + Control.UpdateLayout (); + } + + void OnSelectionChanged (object sender, SelectionChangedEventArgs e) + { + if (Element == null) + return; + + Page page = (e.AddedItems.Count > 0) ? (Page) e.AddedItems[0] : null; + Element.CurrentPage = page; + } + + void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == "CurrentPage") + UpdateCurrentPage (); + } + + void UpdateCurrentPage () + { + Page page = Element.CurrentPage; + UpdateTitle (page); + + if (page == null) + return; + Control.SelectedItem = page; + } + + void OnLoaded (object sender, RoutedEventArgs args) + { + if (Element == null) + return; + + Element.SendAppearing (); + } + + void OnUnloaded (object sender, RoutedEventArgs args) + { + if (Element == null) + return; + + Element.SendDisappearing (); + } + + void OnTrackerUpdated (object sender, EventArgs e) + { + + } + + void UpdateTitle (Page child) + { + Control.ClearValue (Pivot.TitleProperty); + + if (child == null) + return; + var renderer = Platform.GetRenderer (child); + var navigationRenderer = renderer as NavigationPageRenderer; + if (navigationRenderer != null) { + Control.Title = navigationRenderer.Title; + } else { + ((ITitleProvider) this).ShowTitle = false; + } + + } + + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePage.cs b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePage.cs new file mode 100644 index 00000000..51dfacc5 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePage.cs @@ -0,0 +1,15 @@ +using System; +using System.ComponentModel; +using Windows.ApplicationModel; + +namespace Xamarin.Forms.Platform.WinRT +{ + public abstract class WindowsPhonePage + : WindowsBasePage + { + protected override Platform CreatePlatform () + { + return new WindowsPhonePlatform (this); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatform.cs b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatform.cs new file mode 100644 index 00000000..7564e673 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatform.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using Windows.UI.ViewManagement; + +namespace Xamarin.Forms.Platform.WinRT +{ + internal sealed class WindowsPhonePlatform + : Platform + { + public WindowsPhonePlatform (Windows.UI.Xaml.Controls.Page page) + : base (page) + { + _status = StatusBar.GetForCurrentView (); + _status.Showing += OnStatusBarShowing; + _status.Hiding += OnStatusBarHiding; + } + + internal override Rectangle WindowBounds + { + get + { + bool landscape = Device.Info.CurrentOrientation.IsLandscape (); + double offset = (landscape) ? _status.OccludedRect.Width : _status.OccludedRect.Height; + + Rectangle original = base.WindowBounds; + return new Rectangle (original.X, original.Y, original.Width - ((landscape) ? offset : 0), original.Height - ((landscape) ? 0 : offset)); + } + } + + readonly StatusBar _status; + + void OnStatusBarHiding (StatusBar sender, object args) + { + UpdatePageSizes (); + } + + void OnStatusBarShowing (StatusBar sender, object args) + { + UpdatePageSizes (); + } + } +} diff --git a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatformServices.cs b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatformServices.cs new file mode 100644 index 00000000..37d2d4fb --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhonePlatformServices.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using Windows.ApplicationModel; +using Windows.Storage; +using Windows.UI.Core; + +namespace Xamarin.Forms.Platform.WinRT +{ + internal class WindowsPhonePlatformServices + : WindowsBasePlatformServices + { + public WindowsPhonePlatformServices (CoreDispatcher dispatcher) + : base (dispatcher) + { + } + + public override Assembly[] GetAssemblies() + { + var files = Package.Current.InstalledLocation.GetFilesAsync().AsTask().Result; + + List<Assembly> assemblies = new List<Assembly> (files.Count); + for (int i = 0; i < files.Count; i++) { + StorageFile file = files[i]; + if (file.Name.Length < 3) + continue; + + string extension = file.Name.Substring (file.Name.Length - 3, 3).ToLower(); + if (extension != "dll" && extension != "exe") + continue; + + try { + Assembly assembly = Assembly.Load (new AssemblyName { Name = Path.GetFileNameWithoutExtension (file.Name) }); + assemblies.Add (assembly); + } catch (IOException) { + } catch (BadImageFormatException) { + } + } + + return assemblies.ToArray(); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs new file mode 100644 index 00000000..a4ae4e94 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs @@ -0,0 +1,72 @@ +using System; +using Windows.UI.Text; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; + +namespace Xamarin.Forms.Platform.WinRT +{ + internal sealed class WindowsPhoneResourcesProvider + : ISystemResourcesProvider + { + public IResourceDictionary GetSystemResources() + { + var windowsResources = Windows.UI.Xaml.Application.Current.Resources; + + var resources = new ResourceDictionary (); + resources[Device.Styles.TitleStyleKey] = GetStyle ("HeaderTextBlockStyle"); + resources[Device.Styles.SubtitleStyleKey] = GetStyle ("SubheaderTextBlockStyle"); + resources[Device.Styles.BodyStyleKey] = GetStyle ("BodyTextBlockStyle"); + resources[Device.Styles.CaptionStyleKey] = GetStyle ("BodyTextBlockStyle"); + resources[Device.Styles.ListItemTextStyleKey] = GetStyle ("ListViewItemTextBlockStyle"); + resources[Device.Styles.ListItemDetailTextStyleKey] = GetStyle ("ListViewItemContentTextBlockStyle"); + return resources; + } + + Style GetStyle (object nativeKey) + { + var style = (Windows.UI.Xaml.Style) Windows.UI.Xaml.Application.Current.Resources[nativeKey]; + + var formsStyle = new Style (typeof (Label)); + foreach (var b in style.Setters) { + var setter = b as Windows.UI.Xaml.Setter; + if (setter == null) + continue; + + // TODO: Need to implement a stealth pass-through for things we don't support + + if (setter.Property == TextBlock.FontSizeProperty) + formsStyle.Setters.Add (Label.FontSizeProperty, setter.Value); + else if (setter.Property == TextBlock.FontFamilyProperty) + formsStyle.Setters.Add (Label.FontFamilyProperty, setter.Value); + else if (setter.Property == TextBlock.FontWeightProperty) + formsStyle.Setters.Add (Label.FontAttributesProperty, ToAttributes (Convert.ToUInt16 (setter.Value))); + else if (setter.Property == TextBlock.TextWrappingProperty) + formsStyle.Setters.Add (Label.LineBreakModeProperty, ToLineBreakMode ((TextWrapping) setter.Value)); + } + + return formsStyle; + } + + static LineBreakMode ToLineBreakMode (TextWrapping value) + { + switch (value) { + case TextWrapping.Wrap: + return LineBreakMode.CharacterWrap; + case TextWrapping.WrapWholeWords: + return LineBreakMode.WordWrap; + default: + case TextWrapping.NoWrap: + return LineBreakMode.NoWrap; + } + } + + static FontAttributes ToAttributes (ushort uweight) + { + if (uweight == FontWeights.Bold.Weight || uweight == FontWeights.SemiBold.Weight || uweight == FontWeights.ExtraBold.Weight) { + return FontAttributes.Bold; + } + + return FontAttributes.None; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT.Phone/Xamarin.Forms.Platform.WinRT.Phone.csproj b/Xamarin.Forms.Platform.WinRT.Phone/Xamarin.Forms.Platform.WinRT.Phone.csproj new file mode 100644 index 00000000..3bd9cce7 --- /dev/null +++ b/Xamarin.Forms.Platform.WinRT.Phone/Xamarin.Forms.Platform.WinRT.Phone.csproj @@ -0,0 +1,144 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.30703</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{3361D52C-2E74-433E-8285-9C9A5C485977}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Xamarin.Forms.Platform.WinRT</RootNamespace> + <AssemblyName>Xamarin.Forms.Platform.WinRT.Phone</AssemblyName> + <DefaultLanguage>en-US</DefaultLanguage> + <TargetPlatformVersion>8.1</TargetPlatformVersion> + <MinimumVisualStudioVersion>12</MinimumVisualStudioVersion> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\ARM\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <NoWarn>;2008</NoWarn> + <DebugType>full</DebugType> + <PlatformTarget>ARM</PlatformTarget> + <UseVSHostingProcess>false</UseVSHostingProcess> + <ErrorReport>prompt</ErrorReport> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'"> + <OutputPath>bin\ARM\Release\</OutputPath> + <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <Optimize>true</Optimize> + <NoWarn>;2008</NoWarn> + <DebugType>pdbonly</DebugType> + <PlatformTarget>ARM</PlatformTarget> + <UseVSHostingProcess>false</UseVSHostingProcess> + <ErrorReport>prompt</ErrorReport> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x86\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <NoWarn>;2008</NoWarn> + <DebugType>full</DebugType> + <PlatformTarget>x86</PlatformTarget> + <UseVSHostingProcess>false</UseVSHostingProcess> + <ErrorReport>prompt</ErrorReport> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> + <OutputPath>bin\x86\Release\</OutputPath> + <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> + <Optimize>true</Optimize> + <NoWarn>;2008</NoWarn> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x86</PlatformTarget> + <UseVSHostingProcess>false</UseVSHostingProcess> + <ErrorReport>prompt</ErrorReport> + <Prefer32Bit>true</Prefer32Bit> + </PropertyGroup> + <ItemGroup> + <!-- A reference to the entire .Net Framework and Windows SDK are automatically included --> + <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj"> + <Project>{57b8b73d-c3b5-4c42-869e-7b2f17d354ac}</Project> + <Name>Xamarin.Forms.Core</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Platform.WinRT\Xamarin.Forms.Platform.WinRT.csproj"> + <Project>{f3fdd7ac-8899-4e41-bfd7-ec83403e736d}</Project> + <Name>Xamarin.Forms.Platform.WinRT</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Xamarin.Forms.Core\Properties\GlobalAssemblyInfo.cs"> + <Link>Properties\GlobalAssemblyInfo.cs</Link> + </Compile> + <Compile Include="Forms.cs" /> + <Compile Include="FormsPivot.cs" /> + <Compile Include="SearchBarRenderer.cs" /> + <Compile Include="TabbedPageRenderer.cs" /> + <Compile Include="WindowsPhonePlatform.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SearchBox.xaml.cs"> + <DependentUpon>SearchBox.xaml</DependentUpon> + </Compile> + <Compile Include="WindowsPhonePage.cs" /> + <Compile Include="WindowsPhonePlatformServices.cs" /> + <Compile Include="WindowsPhoneResourcesProvider.cs" /> + </ItemGroup> + <ItemGroup> + <Page Include="..\Xamarin.Forms.Platform.WinRT\Resources.xaml"> + <Link>Resources.xaml</Link> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + <Page Include="FormsTextBoxStyle.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Page> + <Page Include="PhoneResources.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Page> + <Page Include="SearchBox.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + </ItemGroup> + <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '12.0' "> + <VisualStudioVersion>12.0</VisualStudioVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(TargetPlatformIdentifier)' == '' "> + <TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier> + </PropertyGroup> + <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project>
\ No newline at end of file |