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()
 {
 }
相关推荐
就是有点傻1 天前
WPF按钮走马灯效果
wpf
zuozewei1 天前
虚拟电厂聚合商平台安全技术体系深度解读
安全·wpf
极客智造1 天前
WPF 自定义控件:AutoGrid 实现灵活自动布局的网格控件
wpf
极客智造1 天前
WPF Grid 布局高效扩展:GridHelpers 附加属性工具类全解析
wpf
张人玉1 天前
WPF 多语言实现完整笔记(.NET 4.7.2)
笔记·.net·wpf·多语言实现·多语言适配
暖馒1 天前
深度剖析串口通讯(232/485)
开发语言·c#·wpf·智能硬件
我要打打代码2 天前
WPF控件(2)
wpf
c#上位机2 天前
wpf之行为
c#·wpf
kylezhao20192 天前
深入浅出地理解 C# WPF 中的属性
hadoop·c#·wpf
全栈开发圈2 天前
干货分享|HarmonyOS核心技术理念
wpf·鸿蒙