• WPF登录界面及程序主界面设计


        本博文为WPF编写的 管理系统登录界面,及几个管理系统主界面设计   先上图看一下效果

    主界面:

      图一:登录界面    

    图片二.登录数据准备中

    现在开始上源码:

    登录界面前台源码:

    <Window x:Class="WPFLoginDemo.LoginWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="登录" Height="300" Width="400" 
            WindowStartupLocation="CenterScreen"
            WindowStyle="None"
            FocusManager.FocusedElement="{Binding ElementName=txt_userName}"
            Loaded="Window_Loaded">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="40"/>
            </Grid.ColumnDefinitions>
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="#5aacf6" Offset="0.0"/>
                    <GradientStop Color="#0056f1" Offset="0.2"/>
                    <GradientStop Color="#13ceff" Offset="0.4"/>
                    <GradientStop Color="#006bff" Offset="0.6"/>
                    <GradientStop Color="#19d5ff" Offset="0.8"/>
                    <GradientStop Color="#5aacf6" Offset="1.0"/>
                </LinearGradientBrush>
            </Grid.Background>
            <TextBlock Grid.Row="2" Grid.ColumnSpan="3" 
                       Text="XXX管理系统V1.1.001版" TextAlignment="Center" 
                       VerticalAlignment="Center" FontSize="22"></TextBlock>
            <TextBlock Grid.Row="3" TextAlignment="Right"  VerticalAlignment="Center"
                       Text="用户名:"/>
            <TextBox Grid.Row="3" Grid.Column="1" Height="27" Margin="5 0 5 0" 
                     Name="txt_userName"/>
            <TextBlock Grid.Row="4" TextAlignment="Right" VerticalAlignment="Center"
                       Text="密  码:"/>
            <PasswordBox Grid.Row="4" Grid.Column="1" Height="27" Margin="5 0 5 0"
                         Name="txt_Pwd"/>
            <StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal">
                <Button Content="登录" Width="70" Margin="30 0 0 0" Height="35"
                        Name="btn_login" Click="btn_login_Click" Foreground="White" FontSize="18" Background="Transparent"/>
                <Button Content="退出" Width="70" Margin="40 0 0 0" Height="35"
                        Name="btn_exit" Click="btn_exit_Click" Background="Transparent" Foreground="White" FontSize="18"/>
            </StackPanel>
        </Grid>
    </Window>

    后台源码

      private void btn_login_Click(object sender, RoutedEventArgs e)
            {
                Splasher.Show(typeof(frmSplash));
                MainWindow mainWindow = new MainWindow();
                this.Close();
                mainWindow.Show();
            }
            private void btn_exit_Click(object sender, RoutedEventArgs e)
            {
                this.Close();
                Environment.Exit(0);
            }

    这里顺便说一下。在登录到主界面时,一般程序都要加载一些配置数据信息,这个一般般比较耗时,为了提高更好的用户体验 我们加载了一个加载提示窗口
    此提示窗口是修改别人。

    第一步:创建一个提示窗口(如图二)(本窗口为Winform窗口),本窗口本打算改为WPF的可是,改了之后发现无法运行,如果谁修改好了 请把源码贴出来学习一下

    窗口后台源码:

    public partial class frmSplash : Form,ISplashForm
        {
            public frmSplash()
            {
                InitializeComponent();
            }
    
            #region ISplashForm
    
            void ISplashForm.SetStatusInfo(string NewStatusInfo)
            {
                lbStatusInfo.Text = NewStatusInfo;
            }
    
            #endregion
        }

    用到的 接口文件:ISplashForm.cs

      public interface ISplashForm
        {
            void SetStatusInfo(string NewStatusInfo);
        }

    实现辅助类:Splasher.cs

      public class Splasher
        {
            private static Form m_SplashForm = null;
            private static ISplashForm m_SplashInterface = null;
            private static Thread m_SplashThread = null;
            private static string m_TempStatus = string.Empty;
    
            /// <summary>
            /// Show the SplashForm
            /// </summary>
            public static void Show(Type splashFormType)
            {
                if (m_SplashThread != null)
                    return;
                if (splashFormType == null)
                {
                    throw (new Exception("splashFormType is null"));
                }
    
                m_SplashThread = new Thread(new ThreadStart(delegate()
                {
                    CreateInstance(splashFormType);
                    Application.Run(m_SplashForm);
                }));
    
                m_SplashThread.IsBackground = true;
                m_SplashThread.SetApartmentState(ApartmentState.STA);
                m_SplashThread.Start();
            }
    
    
    
            /// <summary>
            /// set the loading Status
            /// </summary>
            public static string Status
            {
                set
                {
                    if (m_SplashInterface == null || m_SplashForm == null)
                    {
                        m_TempStatus = value;
                        return;
                    }
                    m_SplashForm.Invoke(
                            new SplashStatusChangedHandle(delegate(string str) { m_SplashInterface.SetStatusInfo(str); }),
                            new object[] { value }
                        );
                }
    
            }
    
            /// <summary>
            /// Colse the SplashForm
            /// </summary>
            public static void Close()
            {
                if (m_SplashThread == null || m_SplashForm == null) return;
    
                try
                {
                    m_SplashForm.Invoke(new MethodInvoker(m_SplashForm.Close));
                }
                catch (Exception)
                {
                }
                m_SplashThread = null;
                m_SplashForm = null;
            }
    
            private static void CreateInstance(Type FormType)
            {
    
                object obj = FormType.InvokeMember(null,
                                    BindingFlags.DeclaredOnly |
                                    BindingFlags.Public | BindingFlags.NonPublic |
                                    BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
                m_SplashForm = obj as Form;
                m_SplashInterface = obj as ISplashForm;
                if (m_SplashForm == null)
                {
                    throw (new Exception("Splash Screen must inherit from System.Windows.Forms.Form"));
                }
                if (m_SplashInterface == null)
                {
                    throw (new Exception("must implement interface ISplashForm"));
                }
    
                if (!string.IsNullOrEmpty(m_TempStatus))
                    m_SplashInterface.SetStatusInfo(m_TempStatus);
            }
    
    
            private delegate void SplashStatusChangedHandle(string NewStatusInfo);
    
        }

    主界面加载耗时的数据

     public MainWindow()
            {
                InitializeComponent();
    
                //登录是使用
                Splasher.Status = "正在准备数据......";
                System.Threading.Thread.Sleep(1000);
    
                Splasher.Status = "正在添加组件......";
                //此处省略部分加载耗时的代码
    
                Splasher.Status = "正在获取数据库数据......";
                System.Threading.Thread.Sleep(1000);
                Splasher.Status = "初始化完毕";
                System.Threading.Thread.Sleep(300);
    
                Splasher.Close();
            }

    主界面布局出来前台源码

    <Window xmlns:my="clr-namespace:WPFLoginDemo.CustomerControl"  x:Class="WPFLoginDemo.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            WindowStartupLocation="CenterScreen"
            Width="1024" Height="768"
            Title="XXX管理系统V1.1.001版" Loaded="Window_Loaded" SizeChanged="Window_SizeChanged">
        <Window.Resources>
            <!--Separator控件模块样式-->
            <Style x:Key="CorrectSeparatorStyle" TargetType="{x:Type Separator}">
                <Setter Property="Background">
                    <Setter.Value>
                        <RadialGradientBrush>
                            <GradientStop Color="#ffffff" Offset="0"/>
                            <GradientStop Color="#ffffff" Offset="0.2"/>
                            <GradientStop Color="#ffffff" Offset="0.3"/>
                            <GradientStop Color="#ffffff" Offset="0.4"/>
                            <GradientStop Color="#0067c9" Offset="1"/>
                        </RadialGradientBrush>
                    </Setter.Value>
                </Setter>
                <Setter Property="Margin" Value="0,2,0,2"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="Height" Value="1"/>
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Separator}">
                           <Border Background="{TemplateBinding Background}">
                            <Line Stretch="Fill" X2="1" Stroke="{TemplateBinding Background}" StrokeThickness="{TemplateBinding Height}"
                                  StrokeStartLineCap="Square" StrokeEndLineCap="Square"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <!--Button控件模块样式-->
            <Style x:Key="buttonStyle" TargetType="{x:Type Button}">
                <Setter Property="Foreground" Value="Black"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Height" Value="43"/>
                <Setter Property="FontSize" Value="20"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <!--修改模板属性-->
                <Setter Property="Template">
                    <Setter.Value>
                        <!--控件模板-->
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border x:Name="fore" BorderThickness="0" CornerRadius="3" BorderBrush="#5555" Background="{TemplateBinding Background}">
                                <ContentPresenter x:Name="content" HorizontalAlignment="Center" VerticalAlignment="Center" 
                                                  Content="{TemplateBinding  Content}">
                                    <ContentPresenter.BitmapEffect>
                                        <DropShadowBitmapEffect Color="#000" Direction="-90" ShadowDepth="2" Softness="0.1" Opacity="0.3"/>
                                    </ContentPresenter.BitmapEffect>
                                </ContentPresenter>
                            </Border>
                            <ControlTemplate.Triggers>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition  Width="150"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="10"/>
            </Grid.ColumnDefinitions>
            <!--菜单栏-->
            <Menu Grid.ColumnSpan="3">
                <MenuItem Header="【基础资料】"/>
                <MenuItem Header="【客户维修】"/>
                <MenuItem Header="【销售管理】"/>
                <MenuItem Header="【报表查询】"/>
                <MenuItem Header="【用户管理】"/>
                <MenuItem Header="【系统设置】"/>
                <MenuItem Header="【帮助】"/>
            </Menu>
            <!--logo图片 Heard 头部-->
            <TextBlock Text="XXX管理系统" Grid.Row="1" Grid.ColumnSpan="3" TextAlignment="Center" 
                       Foreground="#ffffff" Padding="0 8 0 0" FontSize="30" FontWeight="Bold" HorizontalAlignment="Stretch">
                <TextBlock.Background>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                        <GradientStop Color="#5aacf6" Offset="0.0"/>
                         <GradientStop Color="#0056f1" Offset="0.2"/>
                         <GradientStop Color="#13ceff" Offset="0.4"/>
                         <GradientStop Color="#006bff" Offset="0.6"/>
                         <GradientStop Color="#19d5ff" Offset="0.8"/>
                         <GradientStop Color="#5aacf6" Offset="1.0"/>
                    </LinearGradientBrush>
                </TextBlock.Background>
            </TextBlock>
            <!--分割线-->
            <StackPanel Grid.Row="2" Grid.ColumnSpan="3">
                <Separator Style="{StaticResource ResourceKey=CorrectSeparatorStyle}" Height="5" Background="#c0c0c0">
                </Separator>
            </StackPanel>
            <!--主操作区域-->
            <Grid Grid.Row="3" Grid.ColumnSpan="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="170"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <!--左侧菜单栏-->
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="主菜单栏" Padding="0 7 0 0" TextAlignment="Center" FontSize="20" Foreground="#fafafa" FontWeight="Bold" Height="40">
                            <TextBlock.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientStop Color="#f9f9f9" Offset="0"/>
                                    <GradientStop Color="#ababab" Offset="0.3"/>
                                    <GradientStop Color="#b4b4b4" Offset="0.5"/>
                                    <GradientStop Color="#d2d2d2" Offset="0.75"/>
                                    <GradientStop Color="#dedee0" Offset="1"/>
                                </LinearGradientBrush>
                            </TextBlock.Background>
                     </TextBlock>
                    <StackPanel Name="stackPanel1" Orientation="Vertical" Grid.Row="1" ButtonBase.Click="btn_customer_Click">
                        <StackPanel.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                <GradientStop Color="#005fc3" Offset="0"/>
                                <GradientStop Color="#0c70e5" Offset="0.5"/>
                                <GradientStop Color="#008ae5" Offset="1"/>
                            </LinearGradientBrush>
                        </StackPanel.Background>
                        <!--客户维修-->
                        <Button Name="btn_Repair" Content="客户维修" Style="{StaticResource ResourceKey=buttonStyle}" Click="btn_Repair_Click"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--销售管理-->
                        <Button Content="销售管理" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--报表查询-->
                        <Button Content="报表查询" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--基础资料-->
                        <Button Content="基础资料" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--发货处理-->
                        <Button Content="发货处理" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--用户管理-->
                        <Button Content="用户管理" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                        <Separator Height="4" Style="{StaticResource ResourceKey=CorrectSeparatorStyle}"></Separator>
                        <!--系统设置-->
                        <Button Content="系统设置" Style="{StaticResource ResourceKey=buttonStyle}"></Button>
                    </StackPanel>
                </Grid>
                <!--右侧功能处理-->
                <StackPanel Name="stackPanelRight" Grid.Column="1">
                    <StackPanel.Background>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Color="#f3fbfa" Offset="0.0"/>
                            <GradientStop Color="#eef9fa" Offset="0.2"/>
                            <GradientStop Color="#c5e2f5" Offset="0.4"/>
                            <GradientStop Color="#91d3f5" Offset="0.6"/>
                            <GradientStop Color="#8ed4f6" Offset="0.8"/>
                            <GradientStop Color="#7ed0f6" Offset="1.0"/>
                        </LinearGradientBrush>
                    </StackPanel.Background>
                </StackPanel>
            </Grid>
            <!--状态栏-->
            <StatusBar Grid.Row="4" Grid.ColumnSpan="3" VerticalAlignment="Center" Background="Beige">
                <StatusBarItem Content="数据帐套:正式帐套"/>
                <StatusBarItem Content="岗位名称:仓库管理员" Margin="25 0 0 0"/>
                <StatusBarItem Content="登录用户名:系统管理员" Margin="25 0 0 0"/>
                <StatusBarItem Content="登录时间:2013年11月20日 13:54:08 星期一" Margin="25 0 0 0"/>
            </StatusBar>
        </Grid>
    </Window>

    后台源码出来

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                //登录是使用
                Splasher.Status = "正在准备数据......";
                System.Threading.Thread.Sleep(1000);
    
                Splasher.Status = "正在添加组件......";
                //此处省略部分加载耗时的代码
    
                Splasher.Status = "正在获取数据库数据......";
                System.Threading.Thread.Sleep(1000);
                Splasher.Status = "初始化完毕";
                System.Threading.Thread.Sleep(300);
    
                Splasher.Close();
            }
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                btn_Repair_Click(null, null);
            }
            /// <summary>
            /// 获取渐变效果
            /// </summary>
            /// <returns></returns>
            private LinearGradientBrush GetLinearGradientBrush() 
            {
                LinearGradientBrush linearGradient = new LinearGradientBrush();
                linearGradient.StartPoint = new System.Windows.Point(0, 0.5);
                linearGradient.EndPoint = new System.Windows.Point(1, 0.5);
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#0057bf"), 0.0));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4b8acf"), 0.1));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#e2ecf6"), 0.3));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#ffffff"), 0.5));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#e2ecf6"), 0.8));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4b8acf"), 0.1));
                linearGradient.GradientStops.Add(new GradientStop((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#0057bf"), 1.0));
                return linearGradient;
            }
            private void SetButtonDefaultBackgroud() 
            {
                LogicTree(stackPanel1);
            }
            private void LogicTree(object obj)
            {
                if (!(obj is DependencyObject))
                {
                    return;
                }
                foreach (object child in LogicalTreeHelper.GetChildren(obj as DependencyObject))
                {
                    if (child is Button)
                    {
                        Button btn = (Button)child;
                        btn.Background = System.Windows.Media.Brushes.Transparent;
                    }
                    LogicTree(child);
                }
            }
            private double originalHeight = 0.0;
            private void btn_customer_Click(object sender, RoutedEventArgs e)
            {
                originalHeight = stackPanelRight.ActualHeight;
    
                SetButtonDefaultBackgroud();
                Button btn = e.OriginalSource as Button;
                btn.Background = GetLinearGradientBrush();
                UserControl userControl = null;
                stackPanelRight.Children.Clear();
                if (btn.Content.ToString().Equals("客户维修"))
                {
                    userControl = new CustomerRepairUserControl();   
                }  
                stackPanelRight.Children.Add(userControl);
            }
    
            //主界面窗口大小的变化
            private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                if (this.WindowState == WindowState.Maximized)
                {
                    CustomerData.AddHeight = (stackPanelRight.ActualHeight - originalHeight) / 3 + 35.0;
                }
                else
                {
                    CustomerData.AddHeight = 35.0;
                }
    
            }
    
            private void btn_Repair_Click(object sender, RoutedEventArgs e)
            {
                originalHeight = stackPanelRight.ActualHeight;
    
                SetButtonDefaultBackgroud();
                Button btn = btn_Repair;
                btn.Background = GetLinearGradientBrush();
                UserControl userControl = null;
                stackPanelRight.Children.Clear();
                if (btn.Content.ToString().Equals("客户维修"))
                {
                    userControl = new CustomerRepairUserControl();
                }
                stackPanelRight.Children.Add(userControl);
            }

    右侧流程功能处理 为一个布局好UserControl 控件  CustomerRepairUserControl.xaml
    UserControl控件布局 图片:

    <UserControl x:Class="WPFLoginDemo.CustomerControl.CustomerRepairUserControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 xmlns:shape="clr-namespace:WPFLoginDemo.CustomerControl"
                d:DesignHeight="600" d:DesignWidth="850" SizeChanged="UserControl_SizeChanged">
        <UserControl.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0,1" EndPoint="1,1">
                            <GradientStop Color="#c7daea" Offset="0.0"/>
                            <GradientStop Color="#cadcf0" Offset="0.4"/>
                            <GradientStop Color="#d6e9ff" Offset="0.7"/>
                            <GradientStop Color="#eef6ff" Offset="1.0"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Style>
        </UserControl.Resources>
        <Grid Name="grid1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="150"/>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="150"/>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <!--内容填充-->
            <!--客户送修登记-->
            <TextBlock Name="txtB_row" Grid.ColumnSpan="8" Text=""></TextBlock>
            <Button Grid.Column="3" Grid.Row="1" Content="送修登记新增"/>
            <StackPanel Grid.Column="3" Grid.Row="2" Orientation="Vertical">
                <shape:Arrow X1="50" Y1="0" X2="50" Y2="60" Height="60" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <!--送修登记查询-->
            <StackPanel Grid.Column="4" Grid.Row="1" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="1" Content="送修登记查询"/>
            <!--客户检测新增-->
            <Button Grid.Row="3" Grid.Column="3" Content="客户检测新增"/>
            <StackPanel Grid.Row="4" Grid.Column="3" Orientation="Vertical">
                <shape:Arrow X1="50" Y1="0" X2="50" Y2="60" Height="60" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <!--客户检测查询-->
            <StackPanel Grid.Column="4" Grid.Row="3" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="3" Content="客户检测查询"/>
            
            <!--原厂配件登记-->
            <StackPanel Grid.Column="2" Grid.Row="3" Orientation="Horizontal">
                <shape:Arrow X1="150" Y1="20" X2="0" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="1" Grid.Row="3" Content="原厂配件登记"/>
            <StackPanel Grid.Column="2" Grid.Row="2" Orientation="Horizontal">
                <shape:Arrow X1="150" Y1="60" X2="0" Y2="0" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="1" Grid.Row="1" Content="异常单据查找"/>
            <!--主要报表查询-->
            <Button Grid.Column="1" Grid.Row="5" Content="汇总查询分析"/>
            <Button Grid.Column="1" Grid.Row="7" Content="故障统计分析"/>
            <Button Grid.Column="1" Grid.Row="9" Content="维修记录统计"/>
            <Button Grid.Column="1" Grid.Row="11" Content="快递单打印"/>
            <!--产品报价新增-->
            <Button Grid.Row="5" Grid.Column="3" Content="产品报价新增"/>
            <StackPanel Grid.Row="6" Grid.Column="3" Orientation="Vertical">
                <shape:Arrow X1="50" Y1="0" X2="50" Y2="60" Height="60" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <!--产品报价查询-->
            <StackPanel Grid.Column="4" Grid.Row="5" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="5" Content="产品报价查询"/>
            <!--配件领料新增-->
            <Button Grid.Row="7" Grid.Column="3" Content="配件领料新增"/>
            <StackPanel Grid.Row="8" Grid.Column="3" Orientation="Vertical">
                <shape:Arrow X1="50" Y1="0" X2="50" Y2="60" Height="60" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <!--配件领料查询-->
            <StackPanel Grid.Column="4" Grid.Row="7" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="7" Content="配件领料查询"/>
            <!--维修结案新增-->
            <Button Grid.Row="9" Grid.Column="3" Content="维修结案新增"/>
            <StackPanel Grid.Row="10" Grid.Column="3" Orientation="Vertical">
                <shape:Arrow X1="50" Y1="0" X2="50" Y2="60" Height="60" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <!--维修结案查询-->
            <StackPanel Grid.Column="4" Grid.Row="9" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="9" Content="维修结案查询"/>
            <!--维修发货新增-->
            <Button Grid.Row="11" Grid.Column="3" Content="维修发货新增"/>
            <StackPanel Grid.Column="4" Grid.Row="11" Orientation="Horizontal">
                <shape:Arrow X1="0" Y1="20" X2="150" Y2="20" Width="150" HeadWidth="7" HeadHeight="5" Stroke="Black" StrokeThickness="0.8" />
            </StackPanel>
            <Button Grid.Column="5" Grid.Row="11" Content="维修发货追踪"/>
        </Grid>
    </UserControl>

    下面为 画箭头使用的类

    public sealed class Arrow : Shape
        {
            public static readonly DependencyProperty X1Property = DependencyProperty.Register("X1", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
            public static readonly DependencyProperty Y1Property = DependencyProperty.Register("Y1", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
            public static readonly DependencyProperty X2Property = DependencyProperty.Register("X2", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
            public static readonly DependencyProperty Y2Property = DependencyProperty.Register("Y2", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); 
            public static readonly DependencyProperty HeadWidthProperty = DependencyProperty.Register("HeadWidth", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
            public static readonly DependencyProperty HeadHeightProperty = DependencyProperty.Register("HeadHeight", typeof(double), typeof(Arrow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); 
            [TypeConverter(typeof(LengthConverter))]
            public double X1
            {
                get { return (double)base.GetValue(X1Property); }
                set { base.SetValue(X1Property, value); }
            }
            [TypeConverter(typeof(LengthConverter))]
            public double Y1
            {
                get { return (double)base.GetValue(Y1Property); }
                set { base.SetValue(Y1Property, value); }
            }
            [TypeConverter(typeof(LengthConverter))]
            public double X2
            {
                get { return (double)base.GetValue(X2Property); }
                set { base.SetValue(X2Property, value); }
            }
            [TypeConverter(typeof(LengthConverter))]
            public double Y2
            {
                get { return (double)base.GetValue(Y2Property); }
                set { base.SetValue(Y2Property, value); }
            }
            [TypeConverter(typeof(LengthConverter))]
            public double HeadWidth
            {
                get { return (double)base.GetValue(HeadWidthProperty); }
                set { base.SetValue(HeadWidthProperty, value); }
            }
            [TypeConverter(typeof(LengthConverter))]
            public double HeadHeight
            {
                get { return (double)base.GetValue(HeadHeightProperty); }
                set { base.SetValue(HeadHeightProperty, value); }
            }
            protected override Geometry DefiningGeometry
            {
                get
                {
                    // Create a StreamGeometry for describing the shape
                    StreamGeometry geometry = new StreamGeometry();
                    geometry.FillRule = FillRule.EvenOdd;
    
                    using (StreamGeometryContext context = geometry.Open())
                    {
                        InternalDrawArrowGeometry(context);
                    }
    
                    // Freeze the geometry for performance benefits
                    geometry.Freeze();
    
                    return geometry;
                }
            }        
            private void InternalDrawArrowGeometry(StreamGeometryContext context)
            {
                double theta = Math.Atan2(Y1 - Y2, X1 - X2);
                double sint = Math.Sin(theta);
                double cost = Math.Cos(theta);
    
                Point pt1 = new Point(X1, this.Y1);
                Point pt2 = new Point(X2, this.Y2);
    
                Point pt3 = new Point(
                    X2 + (HeadWidth * cost - HeadHeight * sint),
                    Y2 + (HeadWidth * sint + HeadHeight * cost));
    
                Point pt4 = new Point(
                    X2 + (HeadWidth * cost + HeadHeight * sint),
                    Y2 - (HeadHeight * cost - HeadWidth * sint));
    
                context.BeginFigure(pt1, true, false);
                context.LineTo(pt2, true, true);
                context.LineTo(pt3, true, true);
                context.LineTo(pt2, true, true);
                context.LineTo(pt4, true, true);
            }
            
        
        }
     public class CustomerData
        {
            public static double AddHeight = 35.0;
        }

     本人说水平有限,请批评指正。  

     UserControl 在加入到 主界面是,Width 会随主界面最大化 变大而变大,而Height 侧不会。望大家提出怎么解决。

  • 相关阅读:
    协程greenlet与gevent模块
    进程通信和数据共享两种方式
    创建进程的两个方式
    queue队列吃包子
    queue队列是并发利器
    创建线程方式
    threading线程进程
    socketserver实现多用户并发聊天
    socket实现图片读取
    ZYB's Biology
  • 原文地址:https://www.cnblogs.com/xieyong_198510/p/3435870.html
Copyright © 2020-2023  润新知