繁体   English   中英

调整wpf窗口大小时如何重新加载工具栏

[英]How to reload the toolbar when the wpf window is resized

我在窗口中有一个工具栏,我想使用以下代码在“流程”按钮上隐藏工具栏

private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
    {
        var toolBar = sender as ToolBar;
        if (toolBar != null && !toolBar.HasOverflowItems)
        {
            var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
            if (overflowGrid != null)
            {
                overflowGrid.Visibility = Visibility.Collapsed;
            }
        }
    }

现在,当调整窗口大小时,工具栏实际上可以溢出,然后我想再次触发此加载方法。

如何做到这一点?

有一个SizeChanged事件,我想这就是您要寻找的事件。 在窗口的XAML中:

<Window . . .
        SizeChanged="OnSizeChanged">

然后,在后面的代码中,从OnSizeChanged函数调用现有函数。

或者,您可以像这样引发FrameworkElement_Loaded事件:

RoutedEventArgs args = new RoutedEventArgs( FrameworkElement.LoadedEvent, this );
RaiseEvent(args );

EDIT更正了第二个代码片段,以引发Loaded事件,而不是SizeChanged事件。

暂无
暂无

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

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