diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-06-20 01:58:20 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2018-06-20 01:58:20 +0300 |
| commit | 65d898feb5cadb4bf421f03e40ef3f3109c881a6 (patch) | |
| tree | b2b8b52ec50555ebeaf94f6a56afa12e1e32de8e /Software/Visual_Studio | |
| parent | 0afbbb6b79eca2a780462f9c46f50e705661013c (diff) | |
| download | Tango-65d898feb5cadb4bf421f03e40ef3f3109c881a6.tar.gz Tango-65d898feb5cadb4bf421f03e40ef3f3109c881a6.zip | |
Working on TouchComboBox.
Diffstat (limited to 'Software/Visual_Studio')
11 files changed, 343 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchCheckBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchCheckBox.xaml index 075382863..13aed5ad7 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchCheckBox.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchCheckBox.xaml @@ -15,6 +15,7 @@ <Style TargetType="{x:Type local:TouchCheckBox}"> <Setter Property="Background" Value="{StaticResource TangoPrimaryAccentBrush}"></Setter> <Setter Property="Height" Value="24"></Setter> + <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:TouchCheckBox}"> diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.cs new file mode 100644 index 000000000..83dc42802 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Core.EventArguments; + +namespace Tango.Touch.Controls +{ + public class TouchComboBox : Control + { + static TouchComboBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchComboBox), new FrameworkPropertyMetadata(typeof(TouchComboBox))); + } + + public String Watermark + { + get { return (String)GetValue(WatermarkProperty); } + set { SetValue(WatermarkProperty, value); } + } + public static readonly DependencyProperty WatermarkProperty = + DependencyProperty.Register("Watermark", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null)); + + public object SelectedItem + { + get { return (object)GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } + } + public static readonly DependencyProperty SelectedItemProperty = + DependencyProperty.Register("SelectedItem", typeof(object), typeof(TouchComboBox), new PropertyMetadata(null)); + + public IList ItemsSource + { + get { return (IList)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + public static readonly DependencyProperty ItemsSourceProperty = + DependencyProperty.Register("ItemsSource", typeof(IList), typeof(TouchComboBox), new PropertyMetadata(null)); + + public DataTemplate ItemTemplate + { + get { return (DataTemplate)GetValue(ItemTemplateProperty); } + set { SetValue(ItemTemplateProperty, value); } + } + public static readonly DependencyProperty ItemTemplateProperty = + DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(TouchComboBox), new PropertyMetadata(null)); + + public DataTemplate SelectedItemTemplate + { + get { return (DataTemplate)GetValue(SelectedItemTemplateProperty); } + set { SetValue(SelectedItemTemplateProperty, value); } + } + public static readonly DependencyProperty SelectedItemTemplateProperty = + DependencyProperty.Register("SelectedItemTemplate", typeof(DataTemplate), typeof(TouchComboBox), new PropertyMetadata(null)); + + public String Title + { + get { return (String)GetValue(TitleProperty); } + set { SetValue(TitleProperty, value); } + } + public static readonly DependencyProperty TitleProperty = + DependencyProperty.Register("Title", typeof(String), typeof(TouchComboBox), new PropertyMetadata(null)); + + + public TouchComboBox() + { + this.RegisterForPreviewMouseOrTouchDown(OnMouseDown); + this.RegisterForPreviewMouseOrTouchUp(OnMouseUp); + } + + private void OnMouseUp(object sender, MouseOrTouchEventArgs e) + { + ShowSelectionOnTouchPanel(); + } + + private void OnMouseDown(object sender, MouseOrTouchEventArgs e) + { + System.Windows.Input.Keyboard.Focus(this); + } + + protected override void OnGotFocus(RoutedEventArgs e) + { + base.OnGotFocus(e); + ShowSelectionOnTouchPanel(); + } + + private void ShowSelectionOnTouchPanel() + { + TouchPanel touchPanel = this.FindAncestor<TouchPanel>(); + + if (touchPanel != null) + { + touchPanel.CurrentComboBox = this; + } + } + + internal void SetResultFromTouchPanel(Object selectedObject) + { + SelectedItem = selectedObject; + } + } +} diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml new file mode 100644 index 000000000..d50543c4c --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml @@ -0,0 +1,139 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:components="clr-namespace:Tango.Touch.Components" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:fa="http://schemas.fontawesome.io/icons/" + xmlns:local="clr-namespace:Tango.Touch.Controls"> + + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="../Resources/Colors.xaml" /> + + <ResourceDictionary> + <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> + </ResourceDictionary> + </ResourceDictionary.MergedDictionaries> + + <Style TargetType="{x:Type local:TouchComboBox}"> + <Setter Property="Focusable" Value="True"></Setter> + <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"></Setter> + <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter> + <Setter Property="Title" Value="Select a value"></Setter> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type local:TouchComboBox}"> + <Border Background="{TemplateBinding Background}" + BorderBrush="{TemplateBinding BorderBrush}" + BorderThickness="{TemplateBinding BorderThickness}"> + + <DockPanel Background="Transparent"> + <Border DockPanel.Dock="Bottom" Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=(Validation.HasError),Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock FontSize="12" Foreground="{StaticResource TangoValidationErrorBrush}" Margin="0 5 0 0" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=(Validation.Errors).CurrentItem.ErrorContent}"></TextBlock> + </Border> + + <DockPanel> + <Grid DockPanel.Dock="Bottom" Height="2"> + <Rectangle Height="1" Fill="{StaticResource TangoTextWatermarkBrush}" /> + <Rectangle Height="2" RenderTransformOrigin="0.5,0.5" > + <Rectangle.Style> + <Style TargetType="Rectangle"> + <Setter Property="Fill" Value="{StaticResource TangoPrimaryAccentBrush}"></Setter> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleY="1" ScaleX="0" /> + </Setter.Value> + </Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=IsFocused}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="00:00:0.4" /> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="0" Duration="00:00:0.4" /> + </Storyboard> + </BeginStoryboard> + </DataTrigger.ExitActions> + </DataTrigger> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=IsFocused}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="00:00:0.4" /> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="0" Duration="00:00:0.4" /> + </Storyboard> + </BeginStoryboard> + </DataTrigger.ExitActions> + </DataTrigger> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=(Validation.HasError)}" Value="True"> + <Setter Property="Fill" Value="{StaticResource TangoValidationErrorBrush}"></Setter> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleY="1" ScaleX="1" /> + </Setter.Value> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Rectangle.Style> + </Rectangle> + </Grid> + + <Grid> + <components:Ripple RippleBrush="{StaticResource TangoRippleDarkBrush}" RippleFactor="15"> + <DockPanel> + <fa:ImageAwesome IsHitTestVisible="False" VerticalAlignment="Center" DockPanel.Dock="Right" Icon="ChevronDown" Width="12"> + <fa:ImageAwesome.Style> + <Style TargetType="fa:ImageAwesome"> + <Setter Property="Foreground" Value="{StaticResource TangoTextWatermarkBrush}"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=IsFocused}" Value="True"> + <Setter Property="Foreground" Value="{StaticResource TangoPrimaryAccentBrush}"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </fa:ImageAwesome.Style> + </fa:ImageAwesome> + + <Grid> + <ContentControl Padding="0 0 0 4" FocusVisualStyle="{x:Null}" Content="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=SelectedItem}" ContentTemplate="{TemplateBinding SelectedItemTemplate}" Background="Transparent"></ContentControl> + <TextBlock IsHitTestVisible="False" Text="{TemplateBinding Watermark}" Foreground="{StaticResource TangoTextWatermarkBrush}"> + <TextBlock.Style> + <Style TargetType="TextBlock"> + <Setter Property="Visibility" Value="Hidden"></Setter> + <Style.Triggers> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=SelectedItem}" Value="{x:Null}"></Condition> + <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=local:TouchComboBox},Path=IsFocused}" Value="False"></Condition> + </MultiDataTrigger.Conditions> + <Setter Property="Visibility" Value="Visible"></Setter> + </MultiDataTrigger> + </Style.Triggers> + </Style> + </TextBlock.Style> + </TextBlock> + </Grid> + </DockPanel> + </components:Ripple> + </Grid> + </DockPanel> + </DockPanel> + + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs index fdd676968..6cf11d0e7 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs @@ -118,9 +118,13 @@ namespace Tango.Touch.Controls if (!_isLoaded) { var stack = _items_control.FindChild<StackPanel>(); - _items_control.Bind(ItemsControl.HeightProperty, stack, StackPanel.ActualHeightProperty, BindingMode.OneWay); - _isLoaded = true; - RegisterItemsEvents(); + + if (stack != null) + { + _items_control.Bind(ItemsControl.HeightProperty, stack, StackPanel.ActualHeightProperty, BindingMode.OneWay); + _isLoaded = true; + RegisterItemsEvents(); + } } } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.cs index fa01c207b..7b96042b8 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using Tango.Core.Commands; namespace Tango.Touch.Controls { @@ -16,6 +17,34 @@ namespace Tango.Touch.Controls DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchPanel), new FrameworkPropertyMetadata(typeof(TouchPanel))); } + public TouchPanel() + { + ComboBoxPickedCommand = new RelayCommand((x) => + { + CurrentComboBox.SetResultFromTouchPanel(x); + CurrentComboBox = null; + }); + } + + internal RelayCommand ComboBoxPickedCommand + { + get { return (RelayCommand)GetValue(ComboBoxPickedCommandProperty); } + set { SetValue(ComboBoxPickedCommandProperty, value); } + } + internal static readonly DependencyProperty ComboBoxPickedCommandProperty = + DependencyProperty.Register("ComboBoxPickedCommand", typeof(RelayCommand), typeof(TouchPanel), new PropertyMetadata(null)); + + + + + internal TouchComboBox CurrentComboBox + { + get { return (TouchComboBox)GetValue(CurrentComboBoxProperty); } + set { SetValue(CurrentComboBoxProperty, value); } + } + internal static readonly DependencyProperty CurrentComboBoxProperty = + DependencyProperty.Register("CurrentComboBox", typeof(TouchComboBox), typeof(TouchPanel), new PropertyMetadata(null)); + public bool HasMessageBox { get { return (bool)GetValue(HasMessageBoxProperty); } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.xaml index c079512fa..93f96392a 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchPanel.xaml @@ -11,6 +11,7 @@ <ResourceDictionary> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> + <converters:NullObjectToBooleanConverter x:Key="NullObjectToBooleanConverter" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> @@ -99,6 +100,45 @@ </Border> </Grid> </Grid> + + <!--Combo Boxes--> + <Grid Background="#9E000000"> + <Grid.Style> + <Style TargetType="Grid"> + <Setter Property="Opacity" Value="0"></Setter> + <Setter Property="Visibility" Value="Hidden"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent},Path=CurrentComboBox,Converter={StaticResource NullObjectToBooleanConverter}}" Value="True"> + <Setter Property="Visibility" Value="Visible"></Setter> + <DataTrigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation To="1" Storyboard.TargetProperty="Opacity" Duration="00:00:0.2" /> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + </DataTrigger> + </Style.Triggers> + </Style> + </Grid.Style> + + <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent},Path=CurrentComboBox}" Width="300" Height="100" VerticalAlignment="Center"> + <Border Background="{StaticResource TangoPrimaryBackgroundBrush}" CornerRadius="10" Margin="10"> + <Border.Effect> + <DropShadowEffect BlurRadius="10" /> + </Border.Effect> + + <Grid ClipToBounds="True"> + <DockPanel> + <TextBlock DockPanel.Dock="Top" Text="{Binding Title}"></TextBlock> + <local:TouchListBox ItemSelectedCommand="{Binding RelativeSource={RelativeSource AncestorType=local:TouchPanel},Path=ComboBoxPickedCommand}" ItemsSource="{Binding ItemsSource}" SelectionMode="None" ItemTemplate="{Binding ItemTemplate}"> + + </local:TouchListBox> + </DockPanel> + </Grid> + </Border> + </Grid> + </Grid> </Grid> </keyboard:KeyboardView> </Grid> diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchTextBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchTextBox.xaml index ec26d882e..d49f8799e 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchTextBox.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchTextBox.xaml @@ -21,6 +21,7 @@ <Style TargetType="{x:Type local:TouchTextBox}"> <Setter Property="Focusable" Value="False"></Setter> + <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter> <Setter Property="keyboard:KeyboardView.Mode" Value="{Binding RelativeSource={RelativeSource Self},Path=KeyboardMode}"></Setter> <Setter Property="keyboard:KeyboardView.Action" Value="{Binding RelativeSource={RelativeSource Self},Path=KeyboardAction}"></Setter> <Setter Property="keyboard:KeyboardView.Container" Value="{Binding RelativeSource={RelativeSource Self},Path=KeyboardContainer}"></Setter> diff --git a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj index 635e94121..a8febc75c 100644 --- a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj +++ b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj @@ -58,6 +58,7 @@ <ItemGroup> <Compile Include="Controls\MessageBoxVM.cs" /> <Compile Include="Controls\TouchCheckBox.cs" /> + <Compile Include="Controls\TouchComboBox.cs" /> <Compile Include="Controls\TouchInput.cs" /> <Compile Include="Controls\TouchListBox.cs" /> <Compile Include="Controls\TouchListBoxItem.cs" /> @@ -81,6 +82,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="Controls\TouchComboBox.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Controls\TouchListBox.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml index f275cac9f..eb393bd0b 100644 --- a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml @@ -26,6 +26,7 @@ <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchTextBox.xaml" /> <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchListBox.xaml" /> <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchCheckBox.xaml" /> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchComboBox.xaml" /> <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Styles/TouchToggleButton.xaml" /> <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Styles/TouchButton.xaml" /> diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml index 0ebbe52e5..b931fa94a 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml +++ b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml @@ -23,6 +23,8 @@ <touch:TouchCheckBox Margin="0 20 0 0">Keep me signed in</touch:TouchCheckBox> + <touch:TouchComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=Persons}" /> + <touch:TouchListBox Background="White" SelectionMode="Multiple" Height="50" Margin="0 40 0 0" BorderThickness="1" BorderBrush="Black" ItemsSource="{Binding Names}"> <touch:TouchListBox.ItemTemplate> <DataTemplate> diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs index 7c0583288..d6f01033e 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs @@ -83,6 +83,11 @@ namespace Tango.UITests } public int Age { get; set; } + + public override string ToString() + { + return FirstName; + } } /// <summary> |
