Window xaml:
<Window x:Class="wndVerkoopOrderInvoer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Delivery_Manager.DeliveryManager.ViewModel"
xmlns:vw="clr-namespace:Delivery_Manager.DeliveryManager.View"
xmlns:st="clr-namespace:Delivery_Manager.Settings;assembly=Delivery_Manager_Settings"
xmlns:sf="clr-namespace:Microsoft.Surface.Presentation.Controls;assembly=Microsoft.Surface.Presentation"
Title="Bestel" Height="526" Width="1063"
WindowStyle="None" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Window.Resources>
<ResourceDictionary Source="..\ResourceDictionaries\resdictMain.xaml" />
</Window.Resources>
<Grid PreviewKeyDown="cc1_PreviewKeyDown">
<ContentControl Grid.ZIndex="2" Name="cc1" Content="{Binding VMFullScreen}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type vm:VMVerkoopTakeaway}">
<vw:ucVerkoopTakeaway/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:VMFullScreenVerkoop}">
<vw:ucVerkoopOrderInvoer/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:VMFullScreenPayment}">
<vw:ucVerkoopKlantBetaalMethode/>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Grid>
代码背后的代码:
Private Sub cc1_PreviewKeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs)
Try
If e.Key = Key.F12 Then
If TypeOf (Me.cc1.DataContext) Is VMVerkoop Then
Dim vm As VMVerkoop = Me.cc1.DataContext
If TypeOf (vm.VMFullScreen) Is VMVerkoopTakeaway Then
Dim vmv As VMVerkoopTakeaway = vm.VMFullScreen
If vmv Is Nothing Then Exit Sub
If vmv.VMVerkoop.CanBetalen() Then
vmv.VMVerkoop.BetalenCommand.Execute(Nothing)
End If
ElseIf TypeOf (vm.VMFullScreen) Is VMFullScreenPayment Then
Dim vmv As VMFullScreenPayment = vm.VMFullScreen
If vmv Is Nothing Then Exit Sub
If vmv.CanBetalen() Then
vmv.BetalingCommand.Execute(Nothing)
End If
End If
End If
End If
Catch ex As Exception
WriteErrorLog("wndVerkoopOrderInvoer", "cc1_PreviewKeyDown", ex)
End Try
End Sub
这个窗口是使用名为ucVerkoopTakeaway的usercontrol和他的viewmodel启动的,每当我按下键盘上的一个键时,子程序就会正常运行,但是当窗口的datacontext发生变化时(即:我将其中一个用户控件加载到其中)窗口)我不能让子程序运行..我需要在窗口上做一些事情.DataContextChanged ??任何帮助将不胜感激。
谢谢你
答案 0 :(得分:0)
问题已解决,而不是在网格上使用PreviewKeyDown
我在Keyboard.PreviewKeyDown="cc1_PreviewKeyDown"
之后通过调用键ResizeMode="NoResize"
在窗口上使用它。