工具栏上,最小化按钮的实现。工具栏做成的是用户控件。
用户控件的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()
{
}