0

WPF でモーダル ダイアログをシミュレートするには、ウィンドウを表示して次のように呼び出します。Mouse.Capture(dialogBoxArea, CaptureMode.SubTree);

呼び出しが返されますfalse

Mouse.CapturedですnulldialogBoxArea.VisibilityですVisibility.VisibledialogBoxArea.IsEnabledですtrue

行がもう一度呼び出されると、戻りtrue、マウスを正しくキャプチャします。

キャプチャが機能しない原因として、どのような条件が欠けている可能性がありますか?

編集

これが私がこれまでに試したことです。

        if (Mouse.Captured != null)
        {
            // Not called, so presumably, nothing has already captured the mouse
            MessageBox.Show("already captured");
        }

        if (dialogBoxArea.Visibility != Visibility.Visible)
        {
            // Not called
            MessageBox.Show("not visible");
        }

        if (!dialogBoxArea.IsEnabled)
        {
            // Not called
            MessageBox.Show("not enabled");
        }

        // According to documentation, this should release mouse capture from anything that holds it
        Mouse.Capture(null);

        // Attempt to capture the mouse
        if (!Mouse.Capture(dialogBox, CaptureMode.SubTree))
        {
            // This is called
            Mouse.Capture(null);
            Mouse.Capture(dialogBox, CaptureMode.SubTree);
        }
4

1 に答える 1

1

最初の繰り返しとして、私はあなたのクライアントと話をします。

以下は、常に元のウィンドウの上にあるダイアログ オプション ウィンドウを開き、そのウィンドウへの呼び出しをブロックしますが、実行全体をまったく妨げません。あなたの顧客がその行動を見れば、彼はそれに満足するかもしれません.

namespace StackoverflowExample
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }
    void NewWindowAsDialog(object sender, RoutedEventArgs e)
    {
      Window myOwnedDialog = new Window();
      myOwnedDialog.Owner = this;
      myOwnedDialog.ShowDialog();
    }
  }
}

xaml のサブディビジョン (グリッドなど) にウィンドウをロードする方法を説明する別のオプションを後で投稿します。mouscall をフィルタリングするのではなく、その部門にロードされたコンテンツに基づいて、他のすべての呼び出しをフィルタリングできます。フィルタリングによって、論理ツリーとビューツリーの問題が発生する可能性があります。独自のテンプレートを最初から作成する場合にのみ、ツリーを確認する必要があります。

于 2013-05-21T14:23:05.913 に答える