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()
 {
 }
相关推荐
心平气和量大福大6 小时前
C#-WPF-控件-LiveChart图表-线性2(LineSeries)-数据绑定
开发语言·c#·wpf
whn19771 天前
oracle的节点2无法启动asm实例 提示PMON terminating the instance due to error 481
数据库·oracle·wpf
完美火龙篇 四月的友1 天前
WPF 笔迹延迟优化从硬件到软件的全链路分析
wpf
dalong101 天前
WPF:3D立方体
3d·wpf
Xin_ye100863 天前
第三章:内存泄漏的常见“案发现场”
c#·wpf
心平气和量大福大3 天前
C#-WPF-UserControl-生命周期(加载 退出)
开发语言·c#·wpf
czhc11400756633 天前
7.23:Claude code:注册->封表
wpf
心平气和量大福大4 天前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf
listening7774 天前
HarmonyOS 6.1 全场景协同实战:从“单机”到“超级终端”的分布式重构
wpf
心平气和量大福大5 天前
C#-WPF-布局-Grid
c#·wpf·visual studio