优化菜单,通过绑定实体类添加选中事件进行页面跳转

This commit is contained in:
maqiao 2024-11-05 15:50:30 +08:00
parent 7988187bcc
commit a4a745e7b8
2 changed files with 27 additions and 11 deletions

View File

@ -258,18 +258,34 @@ namespace DM_Weight.ViewModels
}
}
private DelegateCommand<ListBox> _selectionCommon;
public DelegateCommand<ListBox> SelectionCommon
private DelegateCommand _selectionCommon;
public DelegateCommand SelectionCommon
{
get => _selectionCommon ?? (_selectionCommon = new DelegateCommand<ListBox>(SelectionMethod));
get => _selectionCommon ?? (_selectionCommon = new DelegateCommand(SelectionMethod));
}
private void SelectionMethod(ListBox viewName)
{
SelectedMenu = viewName.SelectedItem as PremissionDm;
if (SelectedMenu.PremissionName == "退出")
private void SelectionMethod()
{
//SelectedMenu = viewName.SelectedItem as PremissionDm;
//if (SelectedMenu.PremissionName == "退出")
//{
_chkFunction.HIKStopDVRRecord();
// _chkFunction.HIKStopDVRRecord();
// logger.Info($"用户【{Operator?.Nickname}】退出登录");
// Operator = null;
// Reviewer = null;
// _regionManager.RequestNavigate("MainRegion", "LoginWindow");
//}
//else
//{
// //SelectedMenu.Children = SelectedMenu.Children;
// // SelectedChildMenu = SelectedMenu.Children[0];
// if (!_portUtil.Operate)
// {
// _regionManager.RequestNavigate("ContentRegion", SelectedMenu.Children[0].PremissionPath);
// }
//}
if (SelectedMenu != null && SelectedMenu.PremissionName == "退出")
{
logger.Info($"用户【{Operator?.Nickname}】退出登录");
Operator = null;
Reviewer = null;

View File

@ -27,10 +27,10 @@
</Grid.ColumnDefinitions>
<!--<Image Grid.Column="0" Margin="30 0 30 0" HorizontalAlignment="Left" Width="Auto" Height="26" Source="/Images/logo.png" />-->
<TextBlock Text="交接柜管理系统" Grid.Column="0" Margin="30 0 30 0" HorizontalAlignment="Left" Width="Auto" Height="26" Foreground="White" FontSize="20" FontWeight="Bold" />
<ListBox Name="ListBoxName" Grid.Column="1" ItemsSource="{Binding PremissionDmList}" HorizontalAlignment="Right" Cursor="Hand">
<ListBox Name="ListBoxName" Grid.Column="1" SelectedItem="{Binding SelectedMenu}" ItemsSource="{Binding PremissionDmList}" HorizontalAlignment="Right" Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionCommon}" CommandParameter="{Binding ElementName=ListBoxName}"/>
<i:InvokeCommandAction Command="{Binding SelectionCommon}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemsPanel>