繁体   English   中英

C#WPF - 没有集中注意力的Popup

[英]C# WPF - Popup which doesn't get focused

我只是试图制作一个弹出窗口,在角落里显示一条消息。 这个Popup是我用“TopMost”实现的所有其他窗口的顶部,但我似乎无法让不可聚焦的东西工作......

我的PopUp XAML:

<Window x:Class="message.Popup"
    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:message"
    mc:Ignorable="d"
    Title="Popup" Height="129.808" Width="300" Focusable="False" Topmost="True">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="179*"/>
        <ColumnDefinition Width="113*"/>
    </Grid.ColumnDefinitions>
    <Label x:Name="label" Content="" HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top" Width="272" Grid.ColumnSpan="2"/>

</Grid>

我怎么称呼它(来自另一个窗口):

private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
      new Popup(textBox.Text).Show();
}

PopUp代码:

public Popup(string text)
{
      InitializeComponent();

      label.Content = text;
}

您必须将Mainwindow定义为Popup的所有者并将StartupLocation属性居中。 像这样的东西:

            PopUpWindow.Owner = MainWindow;
            PopUpWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

或者,如果您从另一个窗口调用它:

            PopUpWindow.Owner = this;
            PopUpWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

但是我必须说:这不是MVVM,因为你在Window类中存储文本,我强烈建议你开始阅读有关MVVM的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM