【WPF】管理系统选择界面

在这里插入图片描述

前台代码

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ExpenseItDemo"
    xmlns:localValidation="clr-namespace:ExpenseItDemo.Validation"
    x:Class="ExpenseItDemo.MainWindow"
    DataContext="{StaticResource ExpenseData}"
    Title="ExpenseIt Standalone"
    MinWidth="480" MinHeight="260"
    SizeToContent="WidthAndHeight"
    Icon="Watermark.png"
    WindowStartupLocation="CenterScreen">

    <Window.Resources>
            <DataTemplate x:Key="EmployeeItemTemplate">
                <TextBlock Text="{Binding XPath=@Name}" />
            </DataTemplate>
            <DataTemplate x:Key="CostCenterTemplate">
                <TextBlock Text="{Binding XPath=@Name}" />
            </DataTemplate>
    </Window.Resources>

    <Grid>

        <!-- Watermark -->
        <Image Style="{StaticResource WatermarkImage}" />

        <DockPanel>

            <!-- Menu Bar-->
            <Menu AutomationProperties.Name="Expense It Demo" DockPanel.Dock="Top">

                <!-- File Menu-->
                <MenuItem Header="_File">
                    <MenuItem Command="local:MainWindow.CreateExpenseReportCommand"/>
                    <Separator />
                    <MenuItem Command="local:MainWindow.ExitCommand"/>
                </MenuItem>

                <!-- Help Menu-->
                <MenuItem Header="_Help">
                    <MenuItem Command="local:MainWindow.AboutCommand"/>
                </MenuItem>

            </Menu>

            <!-- Data Entry -->
            <Grid Style="{StaticResource WindowContentGrid}">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="250" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <!-- Email Address -->
                <Label Style="{StaticResource Label}" Target="{Binding ElementName=emailTextBox}" Grid.Column="0"
                       Grid.Row="0">
                    _Email:
                </Label>
                <TextBox Name="emailTextBox" AutomationProperties.Name="Email" Style="{StaticResource InputText}" Grid.Column="1" Grid.Row="0">
                    <TextBox.Text>
                        <Binding Path="Alias" UpdateSourceTrigger="PropertyChanged">
                            <!-- SECURITY: Email alias must be valid email address eg xxx@xxx.com -->
                            <Binding.ValidationRules>
                                <localValidation:EmailValidationRule />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                    <TextBox.ToolTip>Enter email.</TextBox.ToolTip>
                </TextBox>

                <!-- Employee Number -->
                <Label Style="{StaticResource Label}" Target="{Binding ElementName=employeeNumberTextBox}"
                       Grid.Column="0" Grid.Row="1">
                    Employee _Number:
                </Label>
                <TextBox Name="employeeNumberTextBox" AutomationProperties.Name="Employee Number" Style="{StaticResource InputText}" Grid.Column="1" Grid.Row="1">
                    <TextBox.Text>
                        <Binding Path="EmployeeNumber" UpdateSourceTrigger="PropertyChanged">
                            <!-- SECURITY: EmployeeNumber must be an int and 5 digits long -->
                            <Binding.ValidationRules>
                                <localValidation:NumberValidationRule IsFixedLength="True" Length="5" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                    <TextBox.ToolTip>Enter employee number.</TextBox.ToolTip>
                </TextBox>

                <!-- Cost Center -->
                <Label Style="{StaticResource Label}" Target="{Binding ElementName=costCenterTextBox}" Grid.Column="0"
                       Grid.Row="2">
                    _Cost Center:
                </Label>
                <ComboBox Name="costCenterTextBox"
                          AutomationProperties.Name="Cost Center"
                          Style="{StaticResource CostCenterList}"
                          Grid.Column="1" Grid.Row="2"
                          ItemTemplate="{StaticResource CostCenterTemplate}"
                          ItemsSource="{Binding Source={StaticResource CostCenters}}"
                          SelectedValue="{Binding Path=CostCenter}"
                          SelectedValuePath="@Number">
                    <ComboBox.ToolTip>
                        <TextBlock>Choose cost center.</TextBlock>
                    </ComboBox.ToolTip>
                    <ComboBox.ItemContainerStyle>
                        <Style>
                            <Setter Property="AutomationProperties.Name" Value="{Binding XPath=@Name}" />
                        </Style>
                    </ComboBox.ItemContainerStyle>
                </ComboBox>

                <!-- Employee Type List -->
                <Label Style="{StaticResource Label}" Target="{Binding ElementName=employeeTypeRadioButtons}"
                       Grid.Column="0" Grid.Row="3">
                    E_mployees:
                </Label>
                <ListBox Name="employeeTypeRadioButtons" AutomationProperties.Name="Employees" Style="{StaticResource HorizontalRadioList}" Grid.Column="1"
                         Grid.Row="3">
                    <ListBoxItem Style="{StaticResource HorizontalRadio}">
                        FTE
                        <ListBoxItem.ToolTip>
                            <TextBlock>FTE employee type</TextBlock>
                        </ListBoxItem.ToolTip>
                    </ListBoxItem>
                    <ListBoxItem Style="{StaticResource HorizontalRadio}">
                        CSG
                        <ListBoxItem.ToolTip>
                            <TextBlock>CSG employee type</TextBlock>
                        </ListBoxItem.ToolTip>
                    </ListBoxItem>
                    <ListBoxItem Style="{StaticResource HorizontalRadio}">
                        Vendor
                        <ListBoxItem.ToolTip>
                            <TextBlock>Vendor employee type</TextBlock>
                        </ListBoxItem.ToolTip>
                    </ListBoxItem>
                </ListBox>  

                <!-- Employee List -->
                <ListBox Style="{StaticResource EmployeeList}"
                         Grid.Column="1" Grid.Row="4"
                         ItemTemplate="{StaticResource EmployeeItemTemplate}"
                         ItemsSource="{Binding Source={StaticResource Employees}}"
                         ItemContainerStyle="{StaticResource EmployeeListItemContainerStyle}"
                         AutomationProperties.Name="Employee Name">
                    <ListBox.ToolTip>
                        <TextBlock>Choose employee name.</TextBlock>
                    </ListBox.ToolTip>
                </ListBox>

                <!-- Create Expense Report -->
                <Button Name="createExpenseReportButton" Style="{StaticResource CommandButton}" Grid.Column="1"
                        Grid.Row="5" Command="local:MainWindow.CreateExpenseReportCommand"
                        AutomationProperties.AcceleratorKey="Ctrl+Shift+C">
                    Create Expense _Report
                    <Button.ToolTip>
                        <TextBlock>Opens a dialog for creating expense report</TextBlock>
                    </Button.ToolTip>
                </Button>

            </Grid>

        </DockPanel>

    </Grid>

</Window>

后台


using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

namespace ExpenseItDemo
{
    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        static MainWindow()
        {
            // Define CreateExpenseReportCommand
            CreateExpenseReportCommand = new RoutedUICommand("_Create Expense Report..." ,"CreateExpenseReport", typeof(MainWindow));
            CreateExpenseReportCommand.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift));

            // Define ExitCommand
            ExitCommand = new RoutedUICommand("E_xit", "Exit", typeof(MainWindow));

            // Define AboutCommand
            AboutCommand = new RoutedUICommand("_About ExpenseIt Standalone", "About", typeof(MainWindow));
        }

        public MainWindow()
        {
            Initialized += MainWindow_Initialized;

            InitializeComponent();

            employeeTypeRadioButtons.SelectionChanged += employeeTypeRadioButtons_SelectionChanged;

            // Bind CreateExpenseReportCommand
            var commandBindingCreateExpenseReport = new CommandBinding(CreateExpenseReportCommand);
            commandBindingCreateExpenseReport.Executed += commandBindingCreateExpenseReport_Executed;
            CommandBindings.Add(commandBindingCreateExpenseReport);

            // Bind ExitCommand
            var commandBindingExitCommand = new CommandBinding(ExitCommand);
            commandBindingExitCommand.Executed += commandBindingExitCommand_Executed;
            CommandBindings.Add(commandBindingExitCommand);

            // Bind AboutCommand
            var commandBindingAboutCommand = new CommandBinding(AboutCommand);
            commandBindingAboutCommand.Executed += commandBindingAboutCommand_Executed;
            CommandBindings.Add(commandBindingAboutCommand);
        }

        private void MainWindow_Initialized(object sender, EventArgs e)
        {
            // Select the first employee type radio button
            employeeTypeRadioButtons.SelectedIndex = 0;
            RefreshEmployeeList();
        }

        private void commandBindingCreateExpenseReport_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var dlg = new CreateExpenseReportDialogBox {Owner = this};
            dlg.ShowDialog();
        }

        private void commandBindingExitCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Close();
        }

        private void commandBindingAboutCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show(
                "ExpenseIt Standalone Sample Application, by the WPF SDK",
                "ExpenseIt Standalone",
                MessageBoxButton.OK,
                MessageBoxImage.Information);
        }

        private void employeeTypeRadioButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RefreshEmployeeList();
        }

        /// <summary>
        ///     Select the employees who have the employment type that is specified
        ///     by the currently checked employee type radio button
        /// </summary>
        private void RefreshEmployeeList()
        {
            var selectedItem = (ListBoxItem) employeeTypeRadioButtons.SelectedItem;

            // Get employees data source
            var employeesDataSrc = (XmlDataProvider) FindResource("Employees");

            // Select the employees who have of the specified employment type
            var query = string.Format(CultureInfo.InvariantCulture, "/Employees/Employee[@Type='{0}']",
                selectedItem.Content);
            employeesDataSrc.XPath = query;

            // Apply the selection
            employeesDataSrc.Refresh();
        }

        #region Commands

        public static RoutedUICommand CreateExpenseReportCommand;
        public static RoutedUICommand ExitCommand;
        public static RoutedUICommand AboutCommand;

        #endregion
    }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值