【问题标题】:Touch Bug in WPF?触摸 WPF 中的错误?
【发布时间】:2014-12-25 11:28:01
【问题描述】:

我做了以下申请(作为测试)

XAML:

<Window x:Class="GUITest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid Background="Transparent">
        <TextBlock Text="openDialog" Background="Red"  HorizontalAlignment="Center" VerticalAlignment="Top" MouseDown="TextBlock_MouseDown" />
    </Grid>
</Window>

C#:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
    {
        OpenFileDialog dlg = new OpenFileDialog();

        Nullable<bool> result = dlg.ShowDialog();

        if (result == true)
        {
            Console.Out.WriteLine(dlg.FileName);
        }
    }
}

我捕获了 mouseDown 事件,因为它捕获了鼠标按钮按下事件和触摸事件。该代码具有鼠标单击的预期行为。触摸给我带来了一些麻烦。

如果我触摸 TextBlock,它会按要求打开一个对话窗口。关闭它后,窗口上的任何触摸都会打开对话框窗口,即使触摸不在 TextBlock 上。

这是一个错误吗?我可以解决这个问题吗?

编辑:我发布了一个解决方法,实际修复仍然有用

【问题讨论】:

  • 我有两个观察结果 - 一,如果你移动窗口,问题就会停止,二,在这样的现实生活中,你可能想要使用一个按钮(我知道这是只是一个测试,所以这是一个有趣的问题)。也许这可以帮助你想出一些东西。
  • 对不起,我找不到任何有用的东西。
  • @hosch250 感谢按钮提示。这并不是问题的真正答案,而是一种解决方法。我希望按钮看起来像一个 TextBlock,所以我重新设计了按钮,很快发布我的解决方案

标签: c# wpf touch


【解决方案1】:

对于遇到同样问题的其他人。这不是解决问题的方法,而是一种解决方法。 我使用了一个按钮并将其重新设置为看起来像 TextBlock

XAML:

<Grid Background="Transparent">
   <Button HorizontalAlignment="Left" VerticalAlignment="Top" Click="Button_Click" Content="openDialog">
        <Button.Template>
            <ControlTemplate TargetType="Button">
                 <ContentPresenter />
            </ControlTemplate>
        </Button.Template>
   </Button>
</Grid>

Button_Click 的代码与 TextBlock_MouseDown 相同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 2011-07-04
    • 2015-11-20
    • 1970-01-01
    相关资源
    最近更新 更多