WPF养老保险日志_主界面
作者:互联网
主界面布局如图
保留了原窗体的自带样式,在头部菜单栏里,自定义了一个退出登入按钮
左边菜单栏不是使用的不是Expander控件,而是直接使用的按钮
,
完整的XAML代码
<Window x:Class="Wpf_TheOldAgeSystem.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:Wpf_TheOldAgeSystem"
mc:Ignorable="d" Title="MainWindow"
WindowStartupLocation="CenterScreen" Height="800" Width="1400">
<Window.Resources>
<!--重写模板-->
<ControlTemplate x:Key="buttonLeft" TargetType="Button">
<!--自定义故事模板:动态资源-->
<ControlTemplate.Resources>
<!--第一个故事板:操作颜色渐变,边框渐变,背景渐变-->
<Storyboard x:Key="storyboardS1">
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.BorderBrush).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
To="0" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.BorderBrush).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
To="0.51" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
To="0" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
To="0.51" Duration="0:0:0.3"/>
</Storyboard>
<!--第二个故事版:-->
<Storyboard x:Key="storyboardS2">
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.BorderBrush).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
To="0.5" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.BorderBrush).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
To="0.51" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Offset)"
To="0.5" Duration="0:0:0.3"/>
<DoubleAnimation Storyboard.TargetName="bdS"
Storyboard.TargetProperty="(Border.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Offset)"
To="0.51" Duration="0:0:0.3"/>
</Storyboard>
<!--第三个故事板-->
<Storyboard x:Key="storyboardS3">
<DoubleAnimation/>
</Storyboard>
</ControlTemplate.Resources>
<!--自定义视觉树-->
<!--左边功能按钮-->
<Border BorderThickness="1" x:Name="bdS" RenderTransformOrigin="0.5,0.5" Padding="0,7,0,7">
<!--边框渐变-->
<Border.BorderBrush>
<!--渐变画刷:使用线性渐变绘制区域。线性渐变沿直线定义渐变-->
<LinearGradientBrush StartPoint="0,1" EndPoint="0,0" >
<!--使用LinearGradientBrush渐变画刷:定义一个渐变画刷,然后需要定义渐变颜色,颜色已直线形式渐变-->
<!--GradientStop:定义渐变颜色与颜色渐变始点-->
<GradientStop Color="Beige" Offset="0"/>
<GradientStop Color="Beige" Offset="1"/>
</LinearGradientBrush>
</Border.BorderBrush>
<!--背景渐变-->
<Border.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFA26DD6" Offset="0.5"/>
<GradientStop Color="#FFA960D3" Offset="0.51"/>
</LinearGradientBrush>
</Border.Background>
<!--内容-->
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextBlock.Foreground="{TemplateBinding Background}" >
</ContentPresenter>
</Border>
<!--触发器-->
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource storyboardS1}"></BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource storyboardS2}"></BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White"></Setter>
</Style>
</Window.Resources>
<DockPanel>
<Border DockPanel.Dock="Top" Height="70" Grid.Row="0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF9B8DFF" Offset="0.5"/>
<GradientStop Color="#FF9B8DFF" Offset="0.5"/>
<GradientStop Color="#FF8374E9" Offset="0.51"/>
</LinearGradientBrush>
</Border.Background>
<Border.Effect>
<DropShadowEffect BlurRadius="20" Color="#FF575B5B" Direction="315" Opacity="0.5" RenderingBias="Performance" ShadowDepth="5"></DropShadowEffect>
</Border.Effect>
<!--<Border.Effect>
<BlurEffect></BlurEffect>
</Border.Effect>-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="25*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="1">
<TextBlock FontSize="40" FontFamily="隶书" Text="养老保健系统}" VerticalAlignment="Center"></TextBlock>
</Border>
<StackPanel Grid.Column="3" Orientation="Horizontal" HorizontalAlignment="Right">
<Border Margin="0,0,20,0">
<DockPanel>
<Image DockPanel.Dock="Left" Source="/Images/MainWindow/mao.jpg" Margin="6">
<Image.Clip>
<RectangleGeometry RadiusX="55" RadiusY="55" Rect="0,0,55,55"/>
</Image.Clip>
</Image>
<Grid DockPanel.Dock="Right">
<Grid.RowDefinitions>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="4*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="4*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock x:Name="textBlock_UserName" Grid.Row="1" FontSize="20" Text="管理员 / 张伟"></TextBlock>
<TextBlock x:Name="textBlock_NewDateTime" Grid.Row="3" FontSize="18" Text="1970-01-01 00:00:00"></TextBlock>
</Grid>
</DockPanel>
</Border>
<Border BorderThickness="1,0,0,0" BorderBrush="White" Height="50" Width="70">
<Border BorderThickness="16,5">
<Image x:Name="button_ExitTheLogin" Source="/Images/MainWindow/退出.png" />
</Border>
</Border>
</StackPanel>
</Grid>
</Border>
<Border DockPanel.Dock="Left" Width="240">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF9B8DFF" Offset="1"/>
<GradientStop Color="#FFFFFFFF" Offset="0"/>
</LinearGradientBrush>
</Border.Background>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid x:Name="grid_ZuoCaiDanLanAnNiu">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Border Tag="0" x:Name="panelBorder">
<!--legtBig-->
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF9B8DFF" Offset="0"/>
<GradientStop Color="#FF8374E9" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FF9B8DFF" Offset="0"/>
<GradientStop Color="Azure" Offset="1"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
<Grid x:Name="Panel" VerticalAlignment="Top">
</Grid>
</Border>
</Grid>
</ScrollViewer>
</Border>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<TabControl x:Name="MainTabControl">
</TabControl>
</ScrollViewer>
</DockPanel>
</Window>
C#代码
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Collections;
using Wpf_TheOldAgeSystem.MyPublicLibrary;
using static System.Windows.Media.ColorConverter;
namespace Wpf_TheOldAgeSystem
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private int _intDownTag = 0;
private readonly UserControlEntscheiden _userControlEntscheiden = new UserControlEntscheiden();
private Hashtable _userInformations;
#region 全局变量
static TabControl TC;//静态选项卡
#endregion
public MainWindow(Hashtable userInformation)
{
InitializeComponent();
TC = MainTabControl;
_userInformations = userInformation;
#region 事件绑定
//button_XiTongWH.Click += Button_CaiTanTianChong;
//button_JieDaiGL.Click += Button_CaiTanTianChong;
//button_FeiYongGL.Click += Button_CaiTanTianChong;
//button_HuShiGZZ.Click += Button_CaiTanTianChong;
//button_YishengGZZ.Click += Button_CaiTanTianChong;
//button_ZongWuGZZ.Click += Button_CaiTanTianChong;
//button_YaoFangGL.Click += Button_CaiTanTianChong;
//button_HoQinGL.Click += Button_CaiTanTianChong;
//button_WuZiGL.Click += Button_CaiTanTianChong;
//button_BaoBiaoZX.Click += Button_CaiTanTianChong;
//button_ChuangKo.Click += Button_CaiTanTianChong;
Loaded += MainWindow_Loaded;
button_ExitTheLogin.MouseLeftButtonDown += Button_ExitTheLogin_MouseLeftButtonDown;
//foreach (UIElement element in stackPanel_ZuoCaiDanLanAnNiu.Children)
//{
// if (element is Button button)
// {
// button.Click += Button_CaiTanTianChong;
// }
//}
#endregion
}
/// <summary>
/// 退出登入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_ExitTheLogin_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (MessageBox.Show("确定要关闭吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information).ToString() !=
"Yes") return;
_userInformations = null;
Properties.Settings.Default.DaranDassIch = false;
Properties.Settings.Default.JobNumberId = string.Empty;
Properties.Settings.Default.JobPassword = string.Empty;
Properties.Settings.Default.comboBox_AreaID = -1;
Properties.Settings.Default.ZiDongDR = false;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
}
/// <summary>
/// 时钟
/// </summary>
private void NewDateTime()
{
var showtimer = new System.Windows.Threading.DispatcherTimer();//实例化
showtimer.Tick += new EventHandler((s, e) =>
{
textBlock_NewDateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//确定时间格式
});
showtimer.Interval = new TimeSpan(0, 0, 0, 1, 0);//控制时间在一秒钟跳动一次
showtimer.Start();//开启
}
/// <summary>
/// 界面加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
//菜单按钮生成
MenuButton();
//时钟绑定
NewDateTime();
//控件属性绑定
ControlpropertyBinding();
}
/// <summary>
/// 控件属性绑定
/// </summary>
private void ControlpropertyBinding()
{
try
{
textBlock_UserName.Text = _userInformations["UserTypeClass"].ToString() + " \\ " + _userInformations["UserMC"].ToString();
}
catch (Exception)
{
new Login().Show();
this.Close();
}
}
/// <summary>
/// 菜单栏按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_CaiTanTianChong(object sender, RoutedEventArgs e)
{
if (_intDownTag == Convert.ToInt32(((Button)sender).Tag) && Panel.Children.Count != 0) Panel.Children.Clear();
else
{
_intDownTag = Convert.ToInt32(((Button)sender).Tag);
Panel.Children.Clear();
Panel.Children.Add(_userControlEntscheiden.MainUserControl(Convert.ToInt32(((Button) sender)?.Tag), _userInformations));
panelBorder.SetValue(Grid.RowProperty, (Convert.ToInt32(((Button) sender)?.GetValue(Grid.RowProperty)) + 1));
}
}
/// <summary>
/// 菜单按钮生成事件
/// </summary>
private void MenuButton()
{
for (var i = 0; i < _userControlEntscheiden.CaiDanButton.Length / 2; i++)
{
var btn = new Button
{
#region 注意事项
//btn.Template
//color转为brush:
// Brush br = new SolidColorBrush(Color.FromRgb(0,0,0));
//string转Color
//(Color)ColorConverter.ConvertFromString((string)str);
//Color转string((Color)value).ToString();
// string和Brush的转换
//Brush color = new SolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));
//Brush转string
// ((Brush)value).ToString();
//string转byte[]
//System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
//byte[] stringBytes = converter.GetBytes(inputString);
//byte[]转string
//System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
#endregion
// ReSharper disable once PossibleNullReferenceException
Foreground = new SolidColorBrush((Color) ConvertFromString("White")),
Tag = i,
Content = _userControlEntscheiden.CaiDanButton[i, 1],
FontWeight = FontWeights.Bold,
FontSize = 14.667,
Padding = new Thickness(0, 5, 0, 5),
Name = _userControlEntscheiden.CaiDanButton[i, 0]
};
//btn.FindName("heasfdadsf");
btn.SetValue(Grid.RowProperty, (i * 2));
grid_ZuoCaiDanLanAnNiu.Children.Add(btn);
//有两种添加网格位置的方式
//Grid.SetColumn(btn,0);
//Grid.SetRow(btn, 5);
btn.RegisterName(_userControlEntscheiden.CaiDanButton[i, 0], btn);
btn.Click += Button_CaiTanTianChong;
}
}
/// <summary>
/// 页面嵌套(添加选项卡)
/// </summary>
/// <param name="sender"></param>
/// <param name="uc"></param>
public static void AddItem(object sender, System.Windows.Controls.UserControl uc)
{
var bolWhetherBe = false;//是否存在当前选项
foreach (var t in TC.Items)
{
if (((TabItem)t).Name != ((Button)sender)?.Content.ToString()) continue;//跳过本次循环
TC.SelectedItem = ((TabItem)t);//选中子选项
bolWhetherBe = true;
break;//跳出循环
}
if (bolWhetherBe != false) return; //直接跳出方法
var ti = new TabItem //创建子选项
{
Name = ((Button)sender)?.Content.ToString(),//名称
Header = ((Button)sender)?.Content.ToString(), //标头名称
Content = uc //子选择里面的内容
};
TC.Items.Add(ti);//添加子选项
TC.SelectedItem = ti;//选中子选项
}
}
}
标签:CaiTanTianChong,养老保险,System,Click,button,new,WPF,Button,日志 来源: https://blog.csdn.net/weixin_44368963/article/details/109960808