Преглед на файлове

添加Material Design主题库

dev1
永攀 张 преди 2 седмици
родител
ревизия
cb64e87efe
променени са 5 файла, в които са добавени 156 реда и са изтрити 15 реда
  1. +39
    -3
      ModbusDemo/App.xaml
  2. +1
    -1
      ModbusDemo/App.xaml.cs
  3. +85
    -11
      ModbusDemo/MainWindow.xaml
  4. +25
    -0
      ModbusDemo/MainWindow.xaml.cs
  5. +6
    -0
      ModbusDemo/ModbusDemo.csproj

+ 39
- 3
ModbusDemo/App.xaml Целия файл

@@ -3,8 +3,44 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ModbusDemo"
xmlns:prism="http://prismlibrary.com/"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
>
<prism:PrismApplication.Resources>
</prism:PrismApplication.Resources>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- 使用捆绑的主题,设置基础主题为浅色,主色为深紫色,次色为酸橙色 -->
<materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="LightBlue" SecondaryColor="Lime" />

<!-- 引用 Material Design 2 的默认样式 -->
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style x:Key="LeftMenuStyle" TargetType="ListBoxItem">
<Setter Property="MinHeight" Value="40"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid>
<Border x:Name="border"></Border>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"></ContentPresenter>
</Grid>

<!--触发器-->
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="border" Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"></Setter>
<Setter TargetName="border" Property="Opacity" Value="0.2"></Setter>
</Trigger>

<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"></Setter>
<Setter TargetName="border" Property="Opacity" Value="0.2"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
</prism:PrismApplication>

+ 1
- 1
ModbusDemo/App.xaml.cs Целия файл

@@ -17,7 +17,7 @@ namespace ModbusDemo
/// <returns>启动页面</returns>
protected override Window CreateShell()
{
return Container.Resolve<Window>();
return Container.Resolve<MainWindow>();
}
/// <summary>
/// 实现控制反转和依赖注入功能


+ 85
- 11
ModbusDemo/MainWindow.xaml Целия файл

@@ -1,12 +1,86 @@
<Window x:Class="ModbusDemo.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ModbusDemo"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
<Window
x:Class="ModbusDemo.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ModbusDemo"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:prism="http://prismlibrary.com/"
Title="MainWindow"
Width="1000"
Height="600"
mc:Ignorable="d">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1"></WindowChrome>
</WindowChrome.WindowChrome>
<md:DialogHost DialogTheme="Inherit" Identifier="RootDialog">

<md:DrawerHost x:Name="drawerHost" IsLeftDrawerOpen="{Binding ElementName=MenuToggleButton, Path=IsChecked}">
<!-- 菜单 -->
<md:DrawerHost.LeftDrawerContent>
<DockPanel MinWidth="220">
<StackPanel Margin="0,20" DockPanel.Dock="Top">

</StackPanel>
<!-- 菜单列表 -->
<ListBox x:Name="lbMenu" ItemsSource="{Binding LeftMenusList}" ItemContainerStyle="{StaticResource LeftMenuStyle}" SelectionChanged="lbMenu_SelectionChanged">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding NagivgCmm}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent">
<md:PackIcon Margin="15,0" HorizontalAlignment="Center" VerticalAlignment="Center" Kind="{Binding Icon}">
</md:PackIcon>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding MenuName}">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</md:DrawerHost.LeftDrawerContent>
<!-- 头部 -->
<DockPanel>
<md:ColorZone
Padding="16"
md:ElevationAssist.Elevation="Dp4"
MouseDoubleClick="ColorZone_MouseDoubleClick"
DockPanel.Dock="Top"
Mode="PrimaryMid">
<DockPanel LastChildFill="True">
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal">

<Button x:Name="btnMin" Content="—" Style="{StaticResource MaterialDesignFlatMidBgButton}" Click="btnMin_Click" />
<Button x:Name="btnMax" Content="☐" Style="{StaticResource MaterialDesignFlatMidBgButton}" Click="btnMax_Click" />
<Button x:Name="btnClose" Content="✕" Style="{StaticResource MaterialDesignFlatMidBgButton}" Click="btnClose_Click" />
</StackPanel>

<StackPanel Orientation="Horizontal">
<ToggleButton x:Name="MenuToggleButton" AutomationProperties.Name="HamburgerToggleButton" IsChecked="False" Style="{StaticResource MaterialDesignHamburgerToggleButton}" />



<TextBlock
Margin="15,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.Name="Mat15.0erial Design In XAML Toolkit"
FontSize="22"
Text="ModBus" />
</StackPanel>
</DockPanel>
</md:ColorZone>

<!-- 区域 -->
<ContentControl prism:RegionManager.RegionName="SrganRegion">
</ContentControl>
</DockPanel>
</md:DrawerHost>
</md:DialogHost>
</Window>

+ 25
- 0
ModbusDemo/MainWindow.xaml.cs Целия файл

@@ -20,5 +20,30 @@ namespace ModbusDemo
{
InitializeComponent();
}

private void btnClose_Click(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}

private void btnMax_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
}

private void btnMin_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}

private void ColorZone_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
}

private void lbMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
drawerHost.IsLeftDrawerOpen = false;
}
}
}

+ 6
- 0
ModbusDemo/ModbusDemo.csproj Целия файл

@@ -13,4 +13,10 @@
<PackageReference Include="Prism.DryIoc" Version="8.1.97" />
</ItemGroup>

<ItemGroup>
<Folder Include="VIew\" />
<Folder Include="VIewModel\" />
<Folder Include="Model\" />
</ItemGroup>

</Project>

Зареждане…
Отказ
Запис