C#进阶 WPF基础二 布局嵌套、菜单、工具栏、多窗口

一、布局的嵌套

布局容器StackPanel 、Grid、DockPanel之间可以相互嵌套

这样可以做成各种各样风格的窗体,功能强大

<Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Button Grid.Row="1" Grid.Column="1"></Button>
            <StackPanel>
                <Button Content="1"></Button>
                <Button Content="2"></Button>
                <Button Content="3"></Button>
            </StackPanel>
            <Grid Grid.Row="0" Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
       
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF 中,如果要使窗口遮住 Windows 任务栏,可以通过以下步骤来实现: 1. 在 Window 对象的 XAML 中,设置 WindowStyle 属性为 None,这将隐藏窗口的标题栏和边框。 ```xaml <Window x:Class="YourNamespace.YourWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Your Window" WindowStyle="None"> <!-- Window Content --> </Window> ``` 2. 在 Window 对象的 XAML 中,设置 WindowState 属性为 Maximized,这将使窗口最大化。 ```xaml <Window x:Class="YourNamespace.YourWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Your Window" WindowStyle="None" WindowState="Maximized"> <!-- Window Content --> </Window> ``` 3. 在代码中,调用 Win32 API 来隐藏任务栏。首先,创建一个名为 "NativeMethods" 的类,并导入以下命名空间: ```csharp using System; using System.Runtime.InteropServices; ``` 4. 在 "NativeMethods" 类中,定义一个名为 "ShowWindow" 的静态方法,用于调用 Win32 API 来显示或隐藏任务栏: ```csharp public static class NativeMethods { [DllImport("user32.dll")] public static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern int ShowWindow(int hwnd, int nCmdShow); } ``` 5. 在窗口的 Loaded 事件处理程序中,调用 "NativeMethods.ShowWindow" 方法来隐藏任务栏。在这之前,需要获取任务栏的窗口句柄并传递给 ShowWindow 方法: ```csharp private void Window_Loaded(object sender, RoutedEventArgs e) { int hwnd = NativeMethods.FindWindow("Shell_TrayWnd", ""); NativeMethods.ShowWindow(hwnd, 0); // 0 表示隐藏任务栏 } ``` 这样,当窗口加载时,它将以全屏模式显示,并且会遮住 Windows 任务栏。请注意,这种方法需要使用 P/Invoke 调用 Win32 API,因此需要添加相应的命名空间和引用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值