XAML==>
<Window x:Class="QueueSystem.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="450" Width="950" WindowStyle="None" Background="{x:Null}" AllowsTransparency="True" MouseLeftButtonDown="DragWindow" WindowStartupLocation="CenterScreen" WindowState="Maximized" Loaded="Window_Loaded"> <Window.Resources> <Style TargetType="{x:Type TextBlock }"> <Setter Property="FontSize" Value="55"/> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="Foreground" Value="White"/> <Setter Property="FontFamily" Value="SimHei"/> <Setter Property="Margin" Value="0,10,0,0"/> <Setter Property="VerticalAlignment" Value="Center"/> </Style> <Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}"> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" /> </Style> </Window.Resources> <Grid> <Image Source="Images/logonBg.jpg" Stretch="Fill"/> <StackPanel Margin="10"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock x:Name="tbHospital" Grid.Column="0" HorizontalAlignment="Left" /> <TextBlock Name="tBlockTime" FontSize="40" Grid.Column="1" HorizontalAlignment="Right" Foreground="Green"/> </Grid> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> </Grid.RowDefinitions> <DataGrid Grid.Row="0" RowHeaderWidth="0" x:Name="dgvList" AlternationCount="2" AutoGenerateColumns="False" FontSize="50" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" HorizontalScrollBarVisibility="Hidden" EnableRowVirtualization="False" IsEnabled="True" EnableColumnVirtualization="False" VerticalGridLinesBrush="#FFBCC1BC" HorizontalGridLinesBrush="#FFBCC1BC"> <DataGrid.ColumnHeaderStyle> <Style TargetType="DataGridColumnHeader"> <Setter Property="FontFamily" Value="SimHei"/> <Setter Property="Foreground" Value="#104E8B"/> <Setter Property="FontSize" Value="50" /> <Setter Property="Height" Value="Auto" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> </DataGrid.ColumnHeaderStyle> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="ItemsControl.AlternationIndex" Value="0"> <Setter Property="Background" Value="#1874CD" /> </Trigger> <Trigger Property="ItemsControl.AlternationIndex" Value="1"> <Setter Property="Background" Value="#1C86EE" /> </Trigger> </Style.Triggers> <Setter Property="Foreground" Value="Yellow"/> <Setter Property="FontFamily" Value="SimHei"/> </Style> </DataGrid.RowStyle> <DataGrid.Columns> <DataGridTextColumn ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Header="检查室" Binding="{Binding QUEUENAME, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> <DataGridTextColumn ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Header="检查部位" Binding="{Binding PARTOFCHECK, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> <DataGridTextColumn ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Header="当前就诊" Binding="{Binding NAME, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> <DataGridTextColumn ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" Header="准备就诊 " Binding="{Binding NAME2, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> </DataGrid.Columns> </DataGrid> </Grid> </StackPanel> <StackPanel> </StackPanel> <TextBlock x:Name="tbCurrentContent" Margin="20" Text="XX人正在就诊......" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom"/> </Grid> </Window>
CS==>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | using System; using System.Collections.Generic; using System.Threading; using System.Windows; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Threading; using QueueSystem.database; using QueueSystem.Helper; namespace QueueSystem { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { private DispatcherTimer DispatcherTimer; public MainWindow() { InitializeComponent(); DispatcherTimer = new System.Windows.Threading.DispatcherTimer(); // 当间隔时间过去时发生的事件 DispatcherTimer.Tick += new EventHandler(ShowCurrentTime); DispatcherTimer.Interval = new TimeSpan(0, 0, 0, 1); DispatcherTimer.Start(); } public void ShowCurrentTime( object sender, EventArgs e) { //获得星期 //this.tBlockTime.Text = DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn")); //this.tBlockTime.Text += "\n"; //获得年月日 //this.tBlockTime.Text = DateTime.Now.ToString("yyyy:MM:dd"); //yyyy年MM月dd日 //this.tBlockTime.Text += "\n"; //获得时分秒 this .tBlockTime.Text = DateTime.Now.ToString( "yyyy-MM-dd HH:mm:ss dddd" ); this .tbCurrentContent.Text = Socket.SocketMSG; } private void DragWindow( object sender, MouseButtonEventArgs e) { this .DragMove(); } private void Window_Loaded( object sender, RoutedEventArgs e) { InitData(); InitSetting(); } /// <summary> /// 初始化配置 /// </summary> private void InitSetting() { string path = AppDomain.CurrentDomain.BaseDirectory + "\\config.xml" ; string hospitalName = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//hospital" , "value" ); string hospitalFontSize = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//hospital" , "fontSize" ); string timeFontSize = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//time" , "fontSize" ); string dgFontSize = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//dataGrid" , "fontSize" ); string currentContentF = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//currentContent" , "fontSize" ); //string serverIp = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//server", "ip"); // string hospitalFont = XmlHelper.Instance.GetAttributeValueByXmlNode(path, "root//server", "port"); this .tbHospital.Text = hospitalName; this .tbHospital.FontSize = double .Parse(hospitalFontSize); this .tBlockTime.FontSize = double .Parse(timeFontSize); this .dgvList.FontSize = double .Parse(dgFontSize); this .tbCurrentContent.FontSize = double .Parse(currentContentF); } /// <summary> /// 初始化数据 /// </summary> private void InitData() { List<QueueSystem.database.Query> list = QUEUEBUSINESS.GetVRqueueList( string .Empty, string .Empty); this .dgvList.ItemsSource = list; } } } public string GetAttributeValueByXmlNode( string path, string nodeName, string attributeName) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode node = doc.SelectSingleNode(nodeName); return node.Attributes[attributeName].Value; } |
配置文件:
<?xml version="1.0" encoding="utf-8" ?> <root> <hospital value="XX省人民医院" fontSize="50"/> <time fontSize="45"/> <dataGrid fontSize="50"/> <currentContent fontSize="50"/> </root>
运行效果:
动态设置DataGrid样式==》 this.dgvList.Foreground = new SolidColorBrush(color); Style style = new System.Windows.Style(); style.TargetType = typeof(DataGridColumnHeader); //foreground Setter hForeGround = new Setter(); hForeGround.Property = ForegroundProperty; Foreground = new SolidColorBrush(headers); hForeGround.Value = Foreground; style.Setters.Add(hForeGround); //HorizontalContentAlignment Setter align = new Setter(); align.Property = HorizontalContentAlignmentProperty; HorizontalAlignment = HorizontalAlignment.Center; HorizontalContentAlignment = HorizontalAlignment; style.Setters.Add(align);
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)