我的WPF应用程序有一个UserControl应该看起来和行为像弹出窗口,但它不是一个窗口.控件不会从Window类中下降的原因是因为它包含第三方虚拟屏幕键盘,并且该控件必须与TextBox它在单击其按钮时将输入字符发送到的控件位于同一窗口中.如果键盘控件不在同一窗口中,则甚至看不到TextBox控件.
拖动对话框时,我遇到的问题是表现糟糕.它足够慢,鼠标离开拖动区域,它停止跟随鼠标.我需要一个更好的方法.
以下是控件的xaml摘录:
<Grid Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Background="{DynamicResource PopupBackground}"
BorderBrush="{DynamicResource PopupBorder}"
BorderThickness="5,5,5,0"
MouseLeftButtonDown="Grid_MouseLeftButtonDown"
MouseLeftButtonUp="Grid_MouseLeftButtonUp"
MouseMove="Grid_MouseMove">
. . .
</Border>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是鼠标事件处理程序:
private void Grid_MouseLeftButtonDown( object sender, MouseButtonEventArgs e ) {
Canvas canvas = Parent as Canvas;
if ( canvas == null ) {
throw new InvalidCastException( "The parent of a KeyboardPopup control must be a Canvas." );
}
DraggingControl = true;
CurrentMousePosition = e.GetPosition( canvas …Run Code Online (Sandbox Code Playgroud)