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()
 {
 }
相关推荐
就是有点傻2 小时前
WPF中ImageBrush和Image的区别
wpf
冷眼Σ(-᷅_-᷄๑)2 小时前
WPF如何使用外部字体
wpf
月落.1 天前
WPF的<ContentControl>控件
wpf
就是有点傻1 天前
WPF中的依赖属性
开发语言·wpf
wangnaisheng1 天前
【WPF】把一个Window放在左上角/右上角顶格显示
wpf
WineMonk1 天前
.NET WPF CommunityToolkit.Mvvm框架
.net·wpf·mvvm
月落.1 天前
WPF中的INotifyPropertyChanged接口
wpf
界面开发小八哥1 天前
界面控件DevExpress WPF中文教程:Data Grid——卡片视图设置
.net·wpf·界面控件·devexpress·ui开发
平凡シンプル1 天前
WPF 打包
wpf
VickyJames1 天前
基于XAML框架和跨平台项目架构设计的深入技术分析
wpf·开源分享·unoplatform·winui3·项目架构