0

I have a custom WPF keyboard that I use for input in my application

xmlns:WpfKb="clr-namespace:WpfKb.Controls;assembly=WpfKb"

And in the resourcedictionary

<WpfKb:OnScreenKeypad x:Key="OnScreenKeypad"/>

In my XAML-code I use the following code to activate:

                    <TextBox Name="Sensor1Yoffset" Width="100" Margin="5,0" Grid.Row="1" Grid.Column="2" Style="{DynamicResource PmEditTextBox}" Text="{Binding Path=SensorOffsetY1}" VerticalContentAlignment="Center"  HorizontalContentAlignment="Center"
                WpfKb:FloatingTouchScreenKeyboard.KeyboardType="{StaticResource OnScreenKeypad}" 
                            WpfKb:FloatingTouchScreenKeyboard.OpenOnFocus="False" 
                            WpfKb:FloatingTouchScreenKeyboard.OpenOnMouseClick="{Binding Path=UseOnScreenKeyboard}" 
                            WpfKb:FloatingTouchScreenKeyboard.Placement="Left" 
                            WpfKb:FloatingTouchScreenKeyboard.PlacementTarget="{Binding ElementName=TheGui}" Grid.ColumnSpan="1" />

Now I need to add this in the code behind, but don't know where ro start looking.

      TextBox ChannelName = new TextBox();
      ChannelName.Style = (MyView.TryFindResource("PmEditTextBox") as Style);
      ChannelName.Width = 300;

The FloatingTouchScreenKeyboardclass is defined as

public partial class FloatingTouchScreenKeyboard : System.Windows.Controls.Primitives.Popup
    {
        public static readonly DependencyProperty AreAnimationsEnabledProperty = DependencyProperty.Register("AreAnimationsEnabled", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty IsAllowedToFadeProperty = DependencyProperty.Register("IsAllowedToFade", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty IsDraggingProperty = DependencyProperty.Register("IsDragging", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(false));
        public static readonly DependencyProperty IsDragHelperAllowedToHideProperty = DependencyProperty.Register("IsDragHelperAllowedToHide", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(false));
        public static readonly DependencyProperty IsKeyboardShownProperty = DependencyProperty.Register("IsKeyboardShown", typeof(bool), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(true));
        public static readonly DependencyProperty MaximumKeyboardOpacityProperty = DependencyProperty.Register("MaximumKeyboardOpacity", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.9d));
        public static readonly DependencyProperty MinimumKeyboardOpacityProperty = DependencyProperty.Register("MinimumKeyboardOpacity", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.2d));
        public static readonly DependencyProperty KeyboardHideDelayProperty = DependencyProperty.Register("KeyboardHideDelay", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(5d));
        public static readonly DependencyProperty KeyboardHideAnimationDurationProperty = DependencyProperty.Register("KeyboardHideAnimationDuration", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.5d));
        public static readonly DependencyProperty KeyboardShowAnimationDurationProperty = DependencyProperty.Register("KeyboardShowAnimationDuration", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(0.5d));
        public static readonly DependencyProperty DeadZoneProperty = DependencyProperty.Register("DeadZone", typeof(double), typeof(FloatingTouchScreenKeyboard), new UIPropertyMetadata(5d));

Any suggestions would be appreciated.

lewi
  • 477
  • 1
  • 5
  • 18

1 Answers1

1

Most of the attached properties you are setting are actually exposed by the floating keyboard's base class, Popup. The Popup class has setter methods you can use to set the properties from C# code, e.g.:

Popup.SetPlacementTarget(ChannelName, TheGui)

For the properties with bindings, use the target's SetBinding method:

ChannelName.SetBinding(
    Popup.OpenOnMouseClickProperty,
    new Binding
    {
        Path = new PropertyPath("UseOnScreenKeyboard")
    });

Looking at the WpfKb project, I do not see any definition for the KeyboardType property. Perhaps it existed in an earlier version, or maybe you are using a customized/forked version?

Mike Strobel
  • 25,075
  • 57
  • 69
  • Excellent. Worked (almost) perfect. I needed to replace Popup with FloatingTouchScreenKeyboard – lewi Oct 27 '14 at 14:23
  • For which property? Most of them were inherited from `Popup`. – Mike Strobel Oct 27 '14 at 14:24
  • For both of them actually. I may be missing a reference or something? The KeyboardType property is defined further down in the code. – lewi Oct 27 '14 at 14:31