我正在开发一款C# WPF应用程序,旨在在全功能Windows 10平板电脑上使用纯触摸方式运行。目前为止,该应用程序的表现很棒,只是我的一个对话框窗口的按钮不太容易被触摸。
对话框窗口 XAML:
<Window x:Class="Commencement_Organizer.ConfirmStudentWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Commencement_Organizer"
mc:Ignorable="d"
Title="Confirmation" Topmost="True" Height="372.677" Width="578.225" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
WindowStyle="None" Background="White" AllowsTransparency="True" Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="00:00:0.2" Storyboard.TargetProperty="Opacity" From="0" To="1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid Background="#FF171717">
<Grid Margin="1" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="YesButton" Content="Yes" Margin="25" Grid.Row="2" Click="YesButton_Click"/>
<Button x:Name="NoButton" Content="No" Margin="25" Grid.Row="2" Grid.Column="1" Click="NoButton_Click"/>
<Label x:Name="label" Content="Confirm your name" Margin="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
<Label x:Name="nameLabel" Content="Label" HorizontalAlignment="Center" Margin="0" Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="2" FontSize="24" FontWeight="Bold"/>
</Grid>
</Grid>
实现(C#):
ConfirmStudentWindow confirmWindow = new ConfirmStudentWindow(student);
confirmWindow.Confirm += OnConfirm;
// This window makes everything behind the dialog window a grey tint, which makes the dialog more prominent
var darkwindow = new Window()
{
Background = Brushes.Black,
Opacity = 0.4,
AllowsTransparency = true,
WindowStyle = WindowStyle.None,
WindowState = WindowState.Maximized,
Topmost = true,
Effect = new BlurEffect()
};
darkwindow.Show(); // Show grey background tint
confirmWindow.ShowDialog(); // Stops main UI thread
darkwindow.Close();
除了在触摸屏上使用这些按钮时它们只是保持高亮,而不实际点击之外,所有功能都按预期工作。使用鼠标完美无误。
在两个不同的Windows 10设备上进行了测试(Surface Pro 2和Surface Book)。
换句话说:
为什么将此窗口作为对话框启动会使其抵抗触摸,但如果将其作为常规窗口启动则不会?
编辑 - 新问题:
除了启动始终保持在顶部的常规窗口并在其后面放置有色覆盖层并提供用户输入结果的事件处理程序之外,是否有模拟对话框窗口的任何方法?