-
Notifications
You must be signed in to change notification settings - Fork 200
【进阶】这是一个Mvc窗口示例
HeBianGu.Window.Link
public partial class App : ApplicationBase
{
protected override MainWindowBase CreateMainWindow(StartupEventArgs e)
{
return new MainWindow();
}
protected override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.AddWindowDialog();
services.AddMessageProxy();
// Do :注册MVC服务
services.AddMvc();
}
protected override void Configure(IApplicationBuilder app)
{
base.Configure(app);
app.UseMainWindowSetting();
// Do:设置默认主题
app.UseLocalTheme(l =>
{
l.AccentColor = (Color)ColorConverter.ConvertFromString("#FF003D99");
l.DefaultFontSize = 14D;
l.FontSize = FontSize.Small;
l.ItemHeight = 36;
l.RowHeight = 40;
//l.ItemWidth = 120;
l.ItemCornerRadius = 5;
l.AnimalSpeed = 5000;
l.AccentColorSelectType = 0;
l.IsUseAnimal = false;
l.ThemeType = ThemeType.Light;
l.Language = Language.Chinese;
l.AccentBrushType = AccentBrushType.LinearGradientBrush;
});
}
}
核心代码
注册服务
IMvcService
protected override System.Windows.Window CreateMainWindow(StartupEventArgs e)
{
return new MainWindow();
}
protected override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
// Do :注册Mvc服务
services.AddMvc();
}
设置样式 Style="{DynamicResource {x:Static h:LinkWindowBase.DefaultKey}}"
Logo="/HeBianGu.General.WpfControlLib;component/Resources/logo.png"
<h:LinkWindowBase x:Class="HeBianGu.Demo.Demo30.MainWindow"
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:h="https://github.com/HeBianGu"
xmlns:local="clr-namespace:HeBianGu.Demo.Demo30"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title=""
CaptionHeight="70"
Style="{DynamicResource {x:Static h:LinkWindowBase.DefaultKey}}"
mc:Ignorable="d">
<h:LinkWindowBase.Links>
<h:LinkAction Action="Home"
Controller="Home"
DisplayName="Home"
Logo="" />
<h:LinkAction Action="Layout"
Controller="Layout"
DisplayName="Layout"
Logo="{x:Null}" />
<h:LinkAction Action="Custom"
Controller="Custom"
DisplayName="Custom"
Logo="{x:Null}" />
<h:LinkAction Action="Set"
Controller="Set"
DisplayName="Set"
Logo="{x:Null}" />
</h:LinkWindowBase.Links>
</h:LinkWindowBase>
添加View->Layout->HomeControl
添加ViewModel->Layout->LayoutViewModel
注意:Layout代表Controller的名称,Home代表Action页面
添加View->Custom->HomeControl
添加ViewModel->Custom->CustomViewModel
添加View->Set->HomeControl
添加ViewModel->>Set-->Set-ViewModel
添加ViewModel->Layout->LayoutViewModel
[ViewModel("Layout")]
internal class LayoutViewModel : MvcViewModelBase
{
}
添加ViewModel->Custom->CustomViewModel
[ViewModel("Custom")]
internal class >CustomViewModel: MvcViewModelBase
{
}
添加ViewModel->Set->SetViewModel
[ViewModel("Set")]
internal class SetViewModel : MvcViewModelBase
{
}
添加View->Custom->HomeControl
添加ViewModel->Custom->CustomViewModel
添加View->Set->HomeControl
添加ViewModel->>Set-->Set-ViewModel
添加Controller->LayoutController->Home
[Controller("Layout")]
internal class LayoutController : Controller<LayoutViewModel>
{
public async Task<IActionResult> Home()
{
return await this.ViewAsync();
}
}
添加Controller->LayoutController->First
添加Controller->LayoutController->Second
添加Controller->CustomController->Home
[Controller("Custom")]
internal class CustomController : Controller<CustomViewModel>
{
public async Task<IActionResult> Home()
{
return await this.ViewAsync();
}
}
添加Controller->SetController->Home
[Controller("Set")]
internal class SetController : Controller<SetViewModel>
{
public async Task<IActionResult> Home()
{
return await this.ViewAsync();
}
}
public async Task<IActionResult> Test()
{
return await this.ViewAsync("First");
return await this.ViewAsync("Second");
return await this.Frist();
}