Skip to content

Commit

Permalink
二级菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
BearXiongLaoXiong committed Aug 20, 2020
1 parent 10ebb93 commit c0bb8db
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 207 deletions.
2 changes: 1 addition & 1 deletion CrazyCoder/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@

<StackPanel Orientation="Horizontal">
<TextBlock Grid.Column="0" Text="{Binding IconFont}" FontFamily="./Fonts/#iconfont" FontSize="22"
Margin="10 0 0 0" Foreground="{Binding BackColor}"/>
Margin="10 0 0 0" Foreground="Red"/>
<TextBlock Margin="10 0 0 0" Text="{Binding Title}" FontSize="14" VerticalAlignment="Center"
Foreground="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1,
AncestorType={x:Type RadioButton}}}" />
Expand Down
59 changes: 59 additions & 0 deletions XCoderWpf/Common/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using HandyControl.Controls;
using XCoderWpf.Models;
using XCoderWpf.ViewModels;
using XCoderWpf.Views;

namespace XCoderWpf.Common
{
public class MainMenu
{
private readonly SolidColorBrush _solidColorBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7F4463"));
private readonly FontFamily _yhFontFamily = new FontFamily("微软雅黑");
private readonly FontFamily _fontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Resources/#iconfont");
private readonly Thickness _margin = new Thickness(10, 0, 0, 0);
private readonly SideMenu _sizeMenu;
private readonly MainWindowViewModel _mainViewViewModel;

public MainMenu(MainWindowViewModel vm, SideMenu sizeMenu) { _mainViewViewModel = vm; _sizeMenu = sizeMenu; }

public void InitializeSystemMenu()
{
var menus = _mainViewViewModel.MainMenuList;
var lvl1Data = menus.Where(x => x.Pid == x.Id).ToList();

_sizeMenu.Items.Clear();
var lvl1MenuList = lvl1Data.Select(x => GetSideMenuItem(x, _yhFontFamily)).ToArray();
_sizeMenu.Items.AddRange(lvl1MenuList);

for (var index = 0; index < lvl1Data.Count; index++)
lvl1MenuList[index].Items.AddRange(menus.Where(x => x.Pid == lvl1Data[index].Id && x.Pid != x.Id).Select(x => GetSideMenuItem(x)));
}

private SideMenuItem GetSideMenuItem(MainMenuModel item, FontFamily fontFamily = null)
{
var side = new SideMenuItem
{
Header = item.Header,
Foreground = _solidColorBrush,
Icon = new TextBlock { Text = item.IconFont, FontFamily = _fontFamily, Margin = _margin, Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(item.BackColor)) },
Tag = item.Tag,
//Command = _mainViewViewModel.SelectCmd,
//CommandParameter = item.Tag,
};
if (fontFamily == null) return side;
side.FontFamily = _yhFontFamily;
side.FontSize = 20;
return side;
}
}
}
21 changes: 21 additions & 0 deletions XCoderWpf/Models/MainMenuModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XCoderWpf.Models
{
public class MainMenuModel
{
public String IconFont { get; set; }

public String Header { get; set; }

public String BackColor { get; set; }

public String Tag { get; set; }
public int Id { get; set; }
public int Pid { get; set; }
}
}
Binary file removed XCoderWpf/Resources/MainMenu/Print.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/Tcp.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/data.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/database.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/database1.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/database2.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/database3.png
Binary file not shown.
Binary file removed XCoderWpf/Resources/MainMenu/file.png
Binary file not shown.
Binary file added XCoderWpf/Resources/iconfont.ttf
Binary file not shown.
32 changes: 32 additions & 0 deletions XCoderWpf/ViewModels/DataBasePublishViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism.Mvvm;

namespace XCoderWpf.ViewModels
{
public class DataBasePublishViewModel : BindableBase
{
private IList<string> _datalist;
public IList<string> DataList
{
get { return _datalist; }
set { SetProperty(ref _datalist, value); }
}
public DataBasePublishViewModel()
{
DataList = new ObservableCollection<string>
{
"mssql111",
"mssql112",
"mssql113",
"mssql114",
"mssql115",
"mssql1117",
};
}
}
}
48 changes: 29 additions & 19 deletions XCoderWpf/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using HandyControl.Controls;
using HandyControl.Data;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using XCoderWpf.Models;
using XCoderWpf.Views;

namespace XCoderWpf.ViewModels
{
public class MainWindowViewModel : BindableBase
{
private readonly IRegionManager _region;
public DelegateCommand<SelectionChangedEventArgs> SwitchItemCommand { get; set; }
public List<MainMenuModel> MainMenuList => new List<MainMenuModel>
{
new MainMenuModel { Id = 0 , Pid = 0 , IconFont = "\xe635", Header = "数据库", BackColor = "#218868" },
new MainMenuModel { Id = 1 , Pid = 0 , IconFont = "\xe635", Header = "数据建模", BackColor = "#218868", Tag = nameof(DataBasePublish) },
new MainMenuModel { Id = 2 , Pid = 0 , IconFont = "\xe6b6", Header = "网络工具", BackColor = "#EE3B3B", Tag = nameof(RegexWindow)},
new MainMenuModel { Id = 3 , Pid = 0 , IconFont = "\xe6e1", Header = "RPC工具", BackColor = "#218868" },

new MainMenuModel { Id = 20, Pid = 20, IconFont = "\xe614", Header = "串口工具", BackColor = "#EE3B3B" },
new MainMenuModel { Id = 21, Pid = 20, IconFont = "\xe755", Header = "地图接口", BackColor = "#218868" },
new MainMenuModel { Id = 22, Pid = 20, IconFont = "\xe635", Header = "正则表达式", BackColor = "#218868", Tag = nameof(RegexWindow) },
new MainMenuModel { Id = 23, Pid = 20, IconFont = "\xe6b6", Header = "图标水印", BackColor = "#EE3B3B" },
new MainMenuModel { Id = 24, Pid = 20, IconFont = "\xe6e1", Header = "加密解密", BackColor = "#218868" },

private String _title = "码神工具";
new MainMenuModel { Id = 50, Pid = 50, IconFont = "\xe614", Header = "语音助手", BackColor = "#EE3B3B" },
new MainMenuModel { Id = 52, Pid = 50, IconFont = "\xe755", Header = "文件夹统计", BackColor = "#218868" },
new MainMenuModel { Id = 53, Pid = 50, IconFont = "\xe635", Header = "文件编码", BackColor = "#218868" }
};

private String _title = "";
public String Title
{
get => _title;
set => SetProperty(ref _title, value);
}

public MainWindowViewModel(IRegionManager regionManager)
{
_region = regionManager;
SwitchItemCommand = new DelegateCommand<SelectionChangedEventArgs>(OnSwitchItem);
}

public DelegateCommand<FunctionEventArgs<object>> SwitchItemCmd => new Lazy<DelegateCommand<FunctionEventArgs<object>>>(() =>
new DelegateCommand<FunctionEventArgs<object>>(SwitchItem)).Value;
private void SwitchItem(FunctionEventArgs<object> info)
{
if (!(info.Info is SideMenuItem item)) return;
_region.RequestNavigate("ContentRegion", item.Tag != null ? item.Tag.ToString() : "Overview");
Growl.Info((info.Info as SideMenuItem)?.Header.ToString());
}
public MainWindowViewModel(IRegionManager regionManager) => _region = regionManager;

public DelegateCommand<FunctionEventArgs<object>> SwitchItemCommand => new Lazy<DelegateCommand<FunctionEventArgs<object>>>(() => new DelegateCommand<FunctionEventArgs<object>>(OnSwitchItem)).Value;
public DelegateCommand<string> SelectCmd => new Lazy<DelegateCommand<string>>(() => new DelegateCommand<string>(Select)).Value;

private void OnSwitchItem(SelectionChangedEventArgs e)


private void OnSwitchItem(FunctionEventArgs<object> info)
{
if (!(e.AddedItems[0] is ListBoxItem item)) return;
if (!(info.Info is SideMenuItem item)) return;
_region.RequestNavigate("ContentRegion", item.Tag != null ? item.Tag.ToString() : "Overview");
}

public DelegateCommand<string> SelectCmd => new Lazy<DelegateCommand<string>>(() =>
new DelegateCommand<string>(Select)).Value;

private void Select(string header) => Growl.Success(header);
}
Expand Down
69 changes: 57 additions & 12 deletions XCoderWpf/Views/DataBasePublish.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
<UserControl x:Class="XCoderWpf.Views.DataBasePublish"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:XCoderWpf.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Style="{StaticResource TextBlockLarge}">ahahahahahaha非常好</TextBlock>
<Button Margin="10" Style="{StaticResource ButtonDanger}"> 11111111111111111</Button>
<Button Margin="10" Style="{StaticResource ButtonSuccess}">2222222222 2221</Button>
<Button Margin="10" Style="{StaticResource ButtonWarning}">2222222222 2221</Button>
xmlns:prism="http://prismlibrary.com/"
xmlns:hc="https://handyorg.github.io/handycontrol"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid Background="{DynamicResource BackgroundBrush}">
<Border Background="{DynamicResource RegionBrush}" Effect="{StaticResource EffectShadow4}" CornerRadius="16" Margin="10">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>

</StackPanel>
<Border Effect="{StaticResource EffectShadow4}" Background="{DynamicResource DarkDefaultBrush}" CornerRadius="16,0,0,16">

<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Vertical">
<hc:ComboBox Margin="30,30,30,0" AutoComplete="True" ShowClearButton="True" ItemsSource="{Binding DataList}" IsEditable="True" hc:InfoElement.Placeholder="请选择" hc:TitleElement.Title="数据库连接"/>

<TextBlock Margin="40,80,0,0" Foreground="White">
<Bold>提示</Bold>path
</TextBlock>

<TextBlock FontWeight="DemiBold" FontSize="22" Foreground="White" Margin="40">
2种用法<LineBreak/>

</TextBlock>
<TextBlock FontWeight="Medium" Margin="40,0" Foreground="{DynamicResource ThirdlyTextBrush}">
1.连接数据库,得到数据表信息<LineBreak/>
2.导入模型,得到数据表信息<LineBreak/>

</TextBlock>
<Image Margin="40,280" Width="46" HorizontalAlignment="Left" Source="{StaticResource Sagittarius}"/>
</StackPanel>
</Border>

<Border Effect="{StaticResource EffectShadow4}" Grid.Column="1" Background="{DynamicResource RegionBrush}" CornerRadius="0,16,16,0">
<StackPanel HorizontalAlignment="Center">
<Image Margin="30" Source="{StaticResource Table}" Width="128"/>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Image Width="24" Source="{StaticResource Graduation}"/>
<TextBlock Margin="5,0" Text="Create an account" FontWeight="Bold" FontSize="14"/>
</StackPanel>
<Button Width="350" Margin="0,40">
<StackPanel Orientation="Horizontal">
<Image Margin="10,0" Source="{StaticResource Google}"/>

<TextBlock Text="Sign up with Google"/>
</StackPanel>
</Button>
<hc:Divider Width="350" Content="OR"/>
<TextBox Style="{StaticResource TextBoxExtend}" hc:TitleElement.Title="Your email" Text="[email protected]"/>
<PasswordBox Style="{StaticResource PasswordBoxExtend}" hc:TitleElement.Title="Set password"/>
<Button Content="Sign up" Style="{DynamicResource ButtonViolet}" Margin="0,30" Width="350"/>
<TextBlock Margin="0,50,0,0" HorizontalAlignment="Center" >
Already have an account? <Button Margin="-4,-10" Content="Sign in" BorderThickness="0" Foreground="Purple" FontWeight="DemiBold" />
</TextBlock>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>
Loading

0 comments on commit c0bb8db

Please sign in to comment.