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?
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:
Presently, this is what I have on pages I want to use the keyboard (see How can I access a control in mvvm model ):
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?