小编Mr.*_*yed的帖子

如何让StackPanel的孩子向下填充最大空间?

我只想在左边流动文本,在右边有一个帮助框.

帮助框应该一直延伸到底部.

如果您取出下面的外部StackPanel,它的效果很好.

但由于布局的原因(我正在动态插入UserControl),我需要包装StackPanel.

如何让GroupBox扩展到StackPanel的底部,你可以看到我已经尝试过:

  • VerticalAlignment = "弹力"
  • VerticalContentAlignment = "弹力"
  • 身高="自动"

XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600">
    <StackPanel 
        VerticalAlignment="Stretch" 
        Height="Auto">

        <DockPanel 
            HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch" 
            Height="Auto" 
            Margin="10">

            <GroupBox 
                DockPanel.Dock="Right" 
                Header="Help" 
                Width="100" 
                Background="Beige" 
                VerticalAlignment="Stretch" 
                VerticalContentAlignment="Stretch" 
                Height="Auto">
                <TextBlock Text="This is the help that is available on the news screen." TextWrapping="Wrap" />
            </GroupBox>

            <StackPanel DockPanel.Dock="Left" Margin="10" Width="Auto" HorizontalAlignment="Stretch">
                <TextBlock Text="Here is the news that should wrap around." TextWrapping="Wrap"/>
            </StackPanel>

        </DockPanel>
    </StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

回答:

谢谢Mark,使用DockPanel而不是StackPanel清理它.一般来说,我发现自己现在越来越多地使用DockPanel进行WPF布局,这里是固定的XAML:

<Window x:Class="TestDynamic033.Test3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Test3" Height="300" Width="600" MinWidth="500" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml dockpanel autoresize autolayout

338
推荐指数
4
解决办法
33万
查看次数

从 Powershell 调用 user32.dll 中的 keybd_event

我试图阻止屏幕保护程序启动。我尝试过发送击键,但它们都需要按标题抓取窗口。如果桌面上没有打开的窗口,则没有什么可抓取的。

所以我找到了一些可能有用的东西,但我不是 C# 向导。它基于在另一个应用程序中模拟按键和按键释放?

下面的代码应该发送 1 但我遗漏了一些东西。在从 Powershell 调用新类型之前,我不会收到任何错误。完成此操作后,我想让它发送 F15 来重置屏幕保护程序倒计时,但不修改屏幕上的内容。(但我得先发送1秒爬行)

Add-Type @"
using System.Runtime.InteropServices;

namespace ConsoleApplication1 
{
    public static class PressKeyForMe 
    { 
        [DllImport("user32.dll")] 
        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

        //public static void Main(string[] args)
        public static void Main()
        {            
            //This code will press and hold the '1' button for 3 secs, and then will release for 1 second
            //VK_F15 0x7E
            keybd_event((byte)0x31, (byte)0x02, 0, UIntPtr.Zero);
            Thread.Sleep(3000);

            keybd_event((byte)0x31, (byte)0x82, (uint)0x2, UIntPtr.Zero);
            Thread.Sleep(1000);
        }
    }

} …
Run Code Online (Sandbox Code Playgroud)

c# powershell

4
推荐指数
1
解决办法
2648
查看次数

标签 统计

autolayout ×1

autoresize ×1

c# ×1

dockpanel ×1

powershell ×1

wpf ×1

xaml ×1