开发者

Making "helper" windows in WPF

I'm writing an app in WPF and want to make a "helper" window. The window needs to be resizable, with no minimize option and doesn't show in the taskbar. If the app receives focus, it should appear as well, but whether or not 开发者_如何转开发it's in front or behind the main window should be retained. When the main window is closed, it should close along with the app.

An example is a detached pane in Visual Studio.

I've made the helper windows not appear in the taskbar, but can't get the rest of the behaviors I want. If they're their own windows, they don't get focus along with the rest of the app. If I specify a the main window as their owner, the main window can't be on top of the helper window.

Anyone know a good way to approach this?


I think what you are looking for is something like a "modeless" dialog box. I don't do WPF, but the description here seems pretty straightforward.

http://msdn.microsoft.com/en-us/library/aa969773.aspx


You could try something like this:

<Window x:Class="HelperWindowDemo.HelperWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="HelperWindow" Height="300" Width="300"
    WindowStyle="ToolWindow"
    ShowInTaskbar="False">
<Grid>
    <TextBlock>Helper window..</TextBlock>
</Grid>

and however you want to show it, something to this effect:

private void AddHelperWindow_Click(object sender, RoutedEventArgs e)
    {
        var window = new HelperWindow { Owner = this };
        window.Show();
    }

its resizable, has no minimize options, doesn't show in the taskbar, appears when the app gets focus, closes with the main window... the only thing it doesn't cover is allowing these tool windows to be behind the main window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜