Cursor = Cursors.None代码中的弹出窗口

时间:2018-05-28 15:57:15

标签: c# wpf

我试图在弹出的代码中将光标设置为none,但我无法使其工作。弹出窗口时,光标仍会显示。我做错了什么?

public void SubWindow_KeyDown(object sender, KeyEventArgs e)
    {

     if (e.Key == Key.Enter)
     {
         TextBlock popupText = new TextBlock();
         popupText.Text = "Complete" ;
         popupText.Background = Brushes.Transparent;
         popupText.Foreground = Brushes.White;          
         popupText.Width = 130;
         popupText.FontSize = 30;
         popupText.IsHitTestVisible = false;
         popupText.Cursor = Cursors.None;

         Popup Popup = new Popup();
         Popup.AllowsTransparency = true;
         Popup.PlacementRectangle = new Rect(1086, 16, 0, 0);
         Popup.IsHitTestVisible = false;
         Popup.Cursor = Cursors.None;

         Popup_Text.Child = popupText;
         Popup.IsOpen = true;
    }

1 个答案:

答案 0 :(得分:1)

不要将IsHitTestVisible的{​​{1}}属性设置为TextBlock

false

另请注意,当光标实际位于您的某个应用元素上时,您的应用只能更改光标。透明TextBlock popupText = new TextBlock(); popupText.Text = "Complete"; popupText.Background = Brushes.Transparent; popupText.Foreground = Brushes.White; popupText.Width = 130; popupText.Height = 130; popupText.FontSize = 30; //popupText.IsHitTestVisible = false; popupText.Cursor = Cursors.None; Popup Popup = new Popup(); //Popup.AllowsTransparency = true; Popup.PlacementRectangle = new Rect(1086, 16, 0, 0); Popup.IsHitTestVisible = false; Popup.Cursor = Cursors.None; Popup.Child = popupText; Popup.IsOpen = true; 的“背景”不属于您的应用程序,因此Popup仅在您将鼠标指针移动到Cursors.None中的实际文本时才适用。