aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Keyboard
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-06-19 14:26:15 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-06-19 14:26:15 +0300
commit6f9da1e19024c7c65d7dbd6038cd34776453f9dc (patch)
tree5bac3f9154c45ea89310b934c64b0788e0598c54 /Software/Visual_Studio/Tango.Touch/Keyboard
parent62dfa96e0bf7cba8b32a0866a0f8101b1e7ec562 (diff)
downloadTango-6f9da1e19024c7c65d7dbd6038cd34776453f9dc.tar.gz
Tango-6f9da1e19024c7c65d7dbd6038cd34776453f9dc.zip
Implemented Touch Panel.
Implemented KeyboardView BringToView routine.
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch/Keyboard')
-rw-r--r--Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.cs97
-rw-r--r--Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.xaml87
2 files changed, 117 insertions, 67 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.cs b/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.cs
index 36bdaced1..af18357c3 100644
--- a/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.cs
+++ b/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.cs
@@ -10,6 +10,7 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
+using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
@@ -25,6 +26,7 @@ namespace Tango.Touch.Keyboard
private static KeyboardView _instance;
private TouchKeyboard keyboard;
+ private Grid gridContent;
#region Properties
@@ -87,24 +89,86 @@ namespace Tango.Touch.Keyboard
private static void RegisterElement(FrameworkElement element)
{
- element.PreviewMouseUp += (_, __) => OnElementFocused(element);
- element.PreviewTouchUp += (_, __) => OnElementFocused(element);
- element.GotFocus += (_, __) => OnElementFocused(element);
- element.LostFocus += (_, __) => OnElementLostFocus(element);
+ element.GotFocus -= Element_GotFocus;
+ element.LostFocus -= Element_LostFocus;
+ element.GotFocus += Element_GotFocus;
+ element.LostFocus += Element_LostFocus;
}
- private async static void OnElementFocused(FrameworkElement element)
+ private static void Element_LostFocus(object sender, RoutedEventArgs e)
{
+ FrameworkElement element = sender as FrameworkElement;
+
+ _instance.IsOpened = false;
+
+ if (GetContainer(element) != null)
+ {
+ ThicknessAnimation ani = new ThicknessAnimation();
+ ani.To = new Thickness(0);
+ ani.Duration = TimeSpan.FromSeconds(0.2);
+ GetContainer(element).BeginAnimation(FrameworkElement.MarginProperty, ani);
+ }
+ }
+
+ private async static void Element_GotFocus(object sender, RoutedEventArgs e)
+ {
+ var element = sender as FrameworkElement;
+
_instance.keyboard.ActionKeyMode = GetAction(element);
_instance.keyboard.Mode = GetMode(element).Value;
- _instance.IsOpened = true;
- await Task.Delay(200);
- element.BringIntoView();
+
+ if (!_instance.IsOpened)
+ {
+ _instance.IsOpened = true;
+ await Task.Delay(200);
+ }
+
+ if (GetContainer(element) != null)
+ {
+ double viewPort = _instance.ActualHeight - _instance.keyboard.ActualHeight;
+ double centerViewPort = viewPort / 2;
+
+ Point relativeLocation = element.TranslatePoint(new Point(0, 0), _instance.gridContent);
+
+ if (relativeLocation.Y + element.ActualHeight + 10 > viewPort || relativeLocation.Y < 0)
+ {
+ double requiredMargin = (relativeLocation.Y + (element.ActualHeight / 2)) - centerViewPort;
+
+ ThicknessAnimation ani = new ThicknessAnimation();
+ ani.To = new Thickness(0, -requiredMargin, 0, requiredMargin);
+ ani.Duration = TimeSpan.FromSeconds(0.2);
+ GetContainer(element).BeginAnimation(FrameworkElement.MarginProperty, ani);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Container
+
+ public static readonly DependencyProperty ContainerProperty =
+ DependencyProperty.RegisterAttached("Container",
+ typeof(FrameworkElement), typeof(KeyboardView),
+ new FrameworkPropertyMetadata(null));
+
+ /// <summary>
+ /// Sets the Container attached property.
+ /// </summary>
+ /// <param name="element">The element.</param>
+ /// <param name="value">if set to <c>true</c> [value].</param>
+ public static void SetContainer(FrameworkElement element, FrameworkElement value)
+ {
+ element.SetValue(ContainerProperty, value);
}
- private static void OnElementLostFocus(FrameworkElement element)
+ /// <summary>
+ /// Gets the Container attached property.
+ /// </summary>
+ /// <param name="element">The element.</param>
+ /// <returns></returns>
+ public static FrameworkElement GetContainer(FrameworkElement element)
{
- _instance.IsOpened = false;
+ return (FrameworkElement)element.GetValue(ContainerProperty);
}
#endregion
@@ -114,17 +178,7 @@ namespace Tango.Touch.Keyboard
public static readonly DependencyProperty ActionProperty =
DependencyProperty.RegisterAttached("Action",
typeof(KeyboardActionKeyMode), typeof(KeyboardView),
- new FrameworkPropertyMetadata(KeyboardActionKeyMode.Tab, ActionChanged));
-
- /// <summary>
- /// Action changed.
- /// </summary>
- /// <param name="d">The d.</param>
- /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
- private static void ActionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- RegisterElement(d as FrameworkElement);
- }
+ new FrameworkPropertyMetadata(KeyboardActionKeyMode.Tab));
/// <summary>
/// Sets the Action attached property.
@@ -167,6 +221,7 @@ namespace Tango.Touch.Keyboard
base.OnApplyTemplate();
keyboard = GetTemplateChild("PART_Keyboard") as TouchKeyboard;
+ gridContent = GetTemplateChild("PART_GridContent") as Grid;
keyboard.ActionKeyPressed += OnActionKeyPressed;
}
diff --git a/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.xaml b/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.xaml
index db5ba6f3d..245c0061d 100644
--- a/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.xaml
+++ b/Software/Visual_Studio/Tango.Touch/Keyboard/KeyboardView.xaml
@@ -3,51 +3,46 @@
xmlns:local="clr-namespace:Tango.Touch.Keyboard">
- <Style TargetType="{x:Type local:KeyboardView}">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type local:KeyboardView}">
- <Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType=local:KeyboardView}}">
- <Grid.RowDefinitions>
- <RowDefinition Height="1*"/>
- <RowDefinition Height="Auto">
- <RowDefinition.Style>
- <Style TargetType="RowDefinition">
- <Setter Property="MaxHeight" Value="0"></Setter>
- <Style.Triggers>
- <DataTrigger Binding="{Binding IsOpened}" Value="True">
- <DataTrigger.EnterActions>
- <BeginStoryboard>
- <Storyboard>
- <DoubleAnimation Storyboard.TargetProperty="MaxHeight" To="1000" Duration="00:00:0.2"></DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </DataTrigger.EnterActions>
- <DataTrigger.ExitActions>
- <BeginStoryboard>
- <Storyboard>
- <DoubleAnimation Storyboard.TargetProperty="MaxHeight" To="0" Duration="00:00:0.1"></DoubleAnimation>
- </Storyboard>
- </BeginStoryboard>
- </DataTrigger.ExitActions>
- </DataTrigger>
- </Style.Triggers>
- </Style>
- </RowDefinition.Style>
- </RowDefinition>
- </Grid.RowDefinitions>
-
- <Grid>
- <ContentPresenter Content="{Binding View}"></ContentPresenter>
- </Grid>
-
- <Grid Grid.Row="1">
- <local:TouchKeyboard x:Name="PART_Keyboard" />
- </Grid>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
+ <Style TargetType="{x:Type local:KeyboardView}">
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="{x:Type local:KeyboardView}">
+ <Grid>
+ <Grid>
+ <Grid x:Name="PART_GridContent">
+ <ContentPresenter Content="{TemplateBinding View}"></ContentPresenter>
+ </Grid>
+ <Grid VerticalAlignment="Bottom" Background="{TemplateBinding Background}">
+ <Grid.Style>
+ <Style TargetType="Grid">
+ <Setter Property="MaxHeight" Value="0"></Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:KeyboardView},Path=IsOpened}" Value="True">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard>
+ <Storyboard>
+ <DoubleAnimation Storyboard.TargetProperty="MaxHeight" To="600" Duration="00:00:0.2"></DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <BeginStoryboard>
+ <Storyboard>
+ <DoubleAnimation Storyboard.TargetProperty="MaxHeight" To="0" Duration="00:00:0.2"></DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Grid.Style>
+ <local:TouchKeyboard x:Name="PART_Keyboard"></local:TouchKeyboard>
+ </Grid>
+ </Grid>
+ </Grid>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
</ResourceDictionary> \ No newline at end of file