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()
 {
 }
相关推荐
huizhixue-IT16 小时前
华为存储考试内容&HCIP-Storage
wpf
桂月二二1 天前
实时事件流处理架构的容错设计
架构·wpf
源之缘-OFD先行者1 天前
GMap.NET + WPF:构建高性能 ADS-B 航空器追踪平台
.net·wpf·ads-b
Marzlam1 天前
WPF学习路线
wpf
weixin_535455792 天前
WPF设计学习记录滴滴滴2
学习·wpf
^@^lemon tea^@^2 天前
WPF 浅述IsHitTestVisible属性
wpf·wpf 穿透
lixy5792 天前
C# WPF 命令机制(关闭CanExecute自动触发,改手动)
c#·wpf
Marzlam2 天前
一文了解WPF技术简介
wpf
arriettyandray2 天前
C#/WPF学习系列之问题记录——使用不流畅
c#·wpf
勘察加熊人3 天前
wpf+c#路径迷宫鼠标绘制
开发语言·c#·wpf