AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-5526349

Andy Wynn's questions

Martin Hope
Andy Wynn
Asked: 2025-02-04 10:42:15 +0800 CST

将控件固定到另一个控件的底部或窗口的底部(以较高者为准)

  • 5

我有这种情况:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="auto"/>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal" Grid.Row="0">
        ...
    </StackPanel>
    <ScrollViewer
        Grid.Row="1"
        HorizontalScrollBarVisibility="Hidden"
        VerticalScrollBarVisibility="Auto">
        <ItemsControl ItemsSource="{Binding Settings}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
            ...
        </ItemsControl>
    </ScrollViewer>
    <Button Content="Add Row" Grid.Row="2" VerticalAlignment="Top"/>
</Grid>

我希望“添加行”按钮停留在 ItemsControl 的底部,但我希望 ItemsControl 开始滚动,而“添加行”按钮固定在窗口底部(因此始终可见),只要行数超出窗口边界。我可以将按钮固定在控件底部,并将第 1 行的行大小设置为“自动”,也可以将其固定在窗口底部,并允许 itemscontrol 以“*”行大小滚动,但我似乎无法同时实现两者。

有没有一个干净的方法来实现这一点?

我确实尝试强制使用 scrollviewer 的 MaxHeight,但很快就变得很糟糕。

wpf
  • 1 个回答
  • 29 Views
Martin Hope
Andy Wynn
Asked: 2023-08-22 22:24:57 +0800 CST

任何菜单关闭时应用程序都会关闭

  • 6

我正在尝试制作一个非常小的应用程序,它仅位于状态栏中,响应键盘快捷键并具有上下文菜单。每当通过选项选择或用户单击关闭此菜单时,都会调用应用程序 OnExit 方法。

我通过在 .NET7 上创建一个新的 WPF 应用程序制作了一个最小版本,删除了MainWindow.xaml,并删除了 中对它的引用App.xaml,然后这是 中的完整代码App.xaml.cs:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;

namespace CLP_MVP;
public partial class App : System.Windows.Application
{
    private readonly NotifyIcon _taskbarIcon = new();
    private readonly ContextMenu _contextMenu = new();
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        _taskbarIcon.Icon = ResourceIcons.clp;
        _taskbarIcon.Visible = true;
        _contextMenu.Items.Add(new MenuItem() { Header = "Test" });
        _taskbarIcon.Click += OpenMenu;
    }

    private void OpenMenu(object? sender, EventArgs e)
        => _contextMenu.IsOpen = true;

    protected override void OnExit(ExitEventArgs e)
        => base.OnExit(e);
}

我点击离开时得到了不一致的结果(我希望在这里有任何见解),但我添加了一个菜单项,其中包含未处理的点击事件,该事件有效地关闭了菜单。

通过框架的调用堆栈是:

>   CLP_MVP.dll!CLP_MVP.App.OnExit(System.Windows.ExitEventArgs e) Line 25  C#
    PresentationFramework.dll!System.Windows.Application.DoShutdown() Line 1582 C#
    PresentationFramework.dll!System.Windows.Application.ShutdownImpl() Line 2210   C#
    PresentationFramework.dll!System.Windows.Application.ShutdownCallback(object arg) Line 2198 C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 103 C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 36 C#
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Line 540  C#
    WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Line 215  C#
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183  C#
    WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 172 C#
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Line 412  C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Line 2095    C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) Line 2304   C#
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) Line 295   C#
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 429    C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 103 C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 36 C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 1339 C#
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(nint hwnd, int msg, nint wParam, nint lParam) Line 341    C#
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Line 2138 C#
    PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Line 2407 C#
    PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Line 1695    C#
    CLP_MVP.dll!CLP_MVP.App.Main() Line 53  C#

对此的任何帮助或想法将不胜感激。我认为这与应用程序生命周期的早期终止有关。由于没有“可见”元素(除了来自不同框架的状态栏图标),应用程序处理程序只是终止执行以避免僵尸进程。如果这个假设是正确的,我将不胜感激关于如何避免这种情况的任何想法。

我尝试过使用Hardcodet.Wpf.TaskbarNotification,结果完全相同。

c#
  • 1 个回答
  • 28 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve