Code Monkey home page Code Monkey logo

wpfkb's People

Contributors

imasm avatar yazgoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wpfkb's Issues

close keyboard at certain times

There are times I want the keyboard to open, and other times I want it to not open. Could you please tell me, how could I do that with wpfkb?

Originally, this is what I used to get the keyboard to be present:

    <keyboard:FloatingTouchScreenKeyboard
        x:Name="Keyboard"
        IsOpen="True"
        Width="1215"
        Height="600"
        VerticalOffset="200"
        PlacementTarget="{Binding ElementName=LoginView}"
        Placement="Center"
        AreAnimationsEnabled="True"
    />

Presently, this is what I have on pages I want to use the keyboard (see How can I access a control in mvvm model ):

public class InspectionCommentViewModel : NotificationStepViewModel
{
    public IInspectionConfirmationView InspectionConfirmationView { get; set; }

    public override void OnNavigatingTo()
    {
        if(HasNotification) _currentText = NotificationComment;

        if (!_inspection.IsCompleted)
        {
            IsOpen = true;
        }

        // The problem is that this view is always null, so I can never show the keyboard
        if (InspectionConfirmationView == null) return;
        {
            InspectionConfirmationView.ShowFloatingKeyboard();
        }
    }
  }

public partial class InspectionComment : UserControl, IInspectionConfirmationView
 {
    private FloatingTouchScreenKeyboard _floatingTouchScreenKeyboard;

    public InspectionComment()
    {
        InitializeComponent();
       
       // The problem is that this DataContext is null, and if I create an instance here it is not the same instance of the InspectionCommentViewModel that gets called elsewhere in the app
        if (DataContext == null)
        {
            DataContext = ServiceLocator.Current.GetInstance<InspectionCommentViewModel>();
        }

        // access you VM by strategy of your framework or choice - this example is when you store your VM in View's DataContext
        (DataContext as InspectionCommentViewModel).InspectionConfirmationView = this as IInspectionConfirmationView;
     }

     public void ShowFloatingKeyboard()
      {
          _floatingTouchScreenKeyboard =
            new FloatingTouchScreenKeyboard()
            {
                IsOpen = true,
                Width = 1215,
                Height = 540,
                Placement = PlacementMode.Center,
                VerticalOffset = 200,
                AreAnimationsEnabled = true
            };

        Binding myBinding =
            new Binding
            {
                ElementName = "InspectionCommentView",
                Source = _floatingTouchScreenKeyboard,
                Path = new PropertyPath("PlacementTarget")
            };

        // Attach to a target property 
        this.SetBinding(FloatingTouchScreenKeyboard.PlacementTargetProperty, myBinding);
    }
 }

So far, I have been trying to follow this pattern to get access to open the keyboard a view, but the problem is that my DataContext is null in the constructor. Is there any way I can get this working without using Caliburn.Micro? The only way I can see how to do it would be to use Caliburn.Micro and call OnViewAttached.

Basically, what I want is to be able to open and close the keyboard from the viewmodel instead of just having it set to open all the time in the XAML. Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.