Skip to content

Commit

Permalink
打开正则窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed May 7, 2020
1 parent 09d49ca commit 4e3ba0c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions CrazyCoder/CrazyCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<Compile Include="Models\MenuModel.cs" />
<Compile Include="Setting.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="Views\Regex.xaml.cs">
<DependentUpon>Regex.xaml</DependentUpon>
<Compile Include="Views\RegexWindow.xaml.cs">
<DependentUpon>RegexWindow.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -77,7 +77,7 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\Regex.xaml">
<Page Include="Views\RegexWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand Down
5 changes: 5 additions & 0 deletions CrazyCoder/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Input;
using CrazyCoder.ViewModels;
using CrazyCoder.Views;

namespace CrazyCoder
{
Expand All @@ -21,6 +22,8 @@ public MainWindow()
private void Regex_Click(Object sender, RoutedEventArgs e)
{
//frame.Navigate(new Uri("Views\\Regex.xaml", UriKind.Relative));
var frm = new RegexWindow();
frm.Show();
}

private void Ico_Click(Object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -59,6 +62,7 @@ private void About_Click(Object sender, RoutedEventArgs e)
}
#endregion

#region 窗口控制
private void Nav_MouseDown(Object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed) DragMove();
Expand All @@ -81,5 +85,6 @@ private void Close_Click(Object sender, RoutedEventArgs e)
{
Close();
}
#endregion
}
}
2 changes: 2 additions & 0 deletions CrazyCoder/Models/MenuModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class MenuModel
public String Title { get; set; }

public String BackColor { get; set; }

public Type Type { get; set; }
}
}
16 changes: 14 additions & 2 deletions CrazyCoder/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Collections.ObjectModel;
using System.Windows;
using CrazyCoder.Models;
using CrazyCoder.Views;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using NewLife.Reflection;

namespace CrazyCoder.ViewModels
{
Expand All @@ -15,7 +18,7 @@ public MainViewModel()
menus.Add(new MenuModel() { IconFont = "\xe6e1", Title = "RPC工具", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe614", Title = "串口工具", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe755", Title = "地图接口", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "正则表达式", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "正则表达式", BackColor = "#218868", Type = typeof(RegexWindow) });
menus.Add(new MenuModel() { IconFont = "\xe6b6", Title = "图标水印", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe6e1", Title = "加密解密", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe614", Title = "语音助手", BackColor = "#EE3B3B" });
Expand Down Expand Up @@ -45,6 +48,15 @@ public MenuModel SelectedMenu

public RelayCommand<MenuModel> SelectedCommand { get; set; }

private void Select(MenuModel model) => SelectedMenu = model;
private void Select(MenuModel model)
{
SelectedMenu = model;

if (model.Type != null)
{
var window = model.Type.CreateInstance() as Window;
window?.Show();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Window x:Class="CrazyCoder.Views.Regex"
<Window x:Class="CrazyCoder.Views.RegexWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CrazyCoder.Views"
mc:Ignorable="d"
Title="Regex" Height="450" Width="800">
Title="正则表达式" Height="450" Width="800">
<Grid>

<TextBlock Text="正则表达式"/>
</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace CrazyCoder.Views
/// <summary>
/// Regex.xaml 的交互逻辑
/// </summary>
public partial class Regex : Window
public partial class RegexWindow : Window
{
public Regex()
public RegexWindow()
{
InitializeComponent();
}
Expand Down

0 comments on commit 4e3ba0c

Please sign in to comment.