wpf,工具栏上,最小化按钮的实现

工具栏上,最小化按钮的实现。工具栏做成的是用户控件。

用户控件的xaml

XML 复制代码
      <Button HorizontalAlignment="Right" Height="32"  Click="MinimizeClick" />

用户控件的cs代码

cs 复制代码
   private void MinimizeClick(object sender, RoutedEventArgs e)
   {
       RaiseEvent(new RoutedEventArgs(MinimizeEvent, this));
   }
cs 复制代码
   public static readonly RoutedEvent MinimizeEvent = EventManager.RegisterRoutedEvent(nameof(Minimize), RoutingStrategy.Bubble,
       typeof(EventHandler<RoutedEventArgs>), typeof(TopBar));

   public event RoutedEventHandler Minimize
   {
       add => AddHandler(MinimizeEvent, value);
       remove => RemoveHandler(MinimizeEvent, value);
   }

用户控件加载到页面后的xaml

XML 复制代码
        <controls:TopBar x:Name="_topBar_" Grid.Row="0"  Close="CloseClick"
                         Maximize="MaximizeClick"
                         Minimize="MinimizeClick"
                         RestoreDown="RestoreDownClick"
                         WindowChrome.IsHitTestVisibleInChrome="True"
                         Show="{Binding SharedViewModel.ShowTopBar,Mode=TwoWay}"
                         MouseMove="TopBarControl_OnMouseMove"
                         HomeButtonIsEnabled ="{Binding SharedViewModel.HomeButtonIsEnabled }"
                         SettingButtonVisibility ="{Binding SharedViewModel.SettingButtonVisibility }"
                         Grid.ColumnSpan="2">
            <be:Interaction.Triggers>
                <be:EventTrigger EventName="Setting">
                    <be:InvokeCommandAction Command="{Binding SettingCommand}" />
                </be:EventTrigger>
                <be:EventTrigger EventName="Home">
                    <be:InvokeCommandAction Command="{Binding HomeCommand}" />
                </be:EventTrigger>
                <be:EventTrigger EventName="Login">
                    <be:InvokeCommandAction Command="{Binding ToLoginCommand}" />
                </be:EventTrigger>
            </be:Interaction.Triggers>
        </controls:TopBar>

.cs代码

XML 复制代码
 HomeCommand = new DelegateCommand(OnHome);

 public DelegateCommand HomeCommand { get; private set; }
 void OnHome()
 {
 }
相关推荐
咩图9 小时前
WPF-VisualStudio-C#-Fluent.Ribbon8.0.0学习
c#·wpf·visual studio
拼尽全力前进10 小时前
JDDL 核心实现原理与架构解析
架构·wpf
加号310 小时前
【C#】WPF基于Halcon 的HWindowControlWPF 控件实现图像缩放、移动
开发语言·c#·wpf
码农的神经元13 小时前
考虑通信时延的直流微电网分布式电-氢混合储能协同控制仿真复现与改进
分布式·wpf
Kimhill张15 小时前
.net core8 WPF 依赖注入(DI)
wpf·.netcore
△曉風殘月〆2 天前
如何在WPF中使用 Fluent 主题
wpf
△曉風殘月〆2 天前
不同.NET版本中的WPF新增功能
.net·wpf
海盗12342 天前
WPF使用内置资源系统实现国际化
wpf
Rotion_深2 天前
WPF UserControl 和 CustomControl
wpf
SEO-狼术2 天前
Run Secure SFTP Across Every Platform
pdf·wpf