EmployeeBrowseView.xaml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <Page x:Class="InvestTracker.Views.EmployeeBrowseView"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:vm="clr-namespace:InvestTracker.VM"
  7. xmlns:local="clr-namespace:InvestTracker.Views"
  8. xmlns:model="clr-namespace:InvestTracker.Entities"
  9. xmlns:validation="clr-namespace:InvestTracker.Validation"
  10. mc:Ignorable="d"
  11. d:DesignHeight="450" d:DesignWidth="800"
  12. x:Name="EPage"
  13. Title="EmployeeBrowseView">
  14. <Page.Resources>
  15. <!--Шаблон яйчейки отображения даты-->
  16. <DataTemplate x:Key="RegularDateTemplate" >
  17. <TextBlock
  18. Text="{Binding Birthday,StringFormat={}{0:dd\.}{0:MM\.}{0:yyyy}}"
  19. VerticalAlignment="Center"
  20. HorizontalAlignment="Center" />
  21. </DataTemplate>
  22. <!--Шаблон яйчейки редактирования даты-->
  23. <DataTemplate x:Key="EditingDateTemplate">
  24. <DatePicker SelectedDate="{Binding Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
  25. </DataTemplate>
  26. </Page.Resources>
  27. <StackPanel>
  28. <!--Этот FrameworkElement содержит все свойства у Page-->
  29. <FrameworkElement x:Name="ProxyElement" DataContext="{Binding}" Visibility="Collapsed"/>
  30. <Menu>
  31. <MenuItem Header="Действие" >
  32. <MenuItem Command="{Binding UndoCommand}" Header="Отменить" ></MenuItem>
  33. <Separator/>
  34. <MenuItem Command="{Binding NewCommand}" Header="Создать" ></MenuItem>
  35. <MenuItem Command="{Binding EditCommand}" Header="Редактировать" ></MenuItem>
  36. <MenuItem Command="{Binding SaveCommand}" Header="Сохранить" ></MenuItem>
  37. <MenuItem Command="{Binding FindCommand}" Header="Найти" />
  38. <Separator/>
  39. <MenuItem Command="{Binding DeleteCommand}" Header="Удалить" ></MenuItem>
  40. </MenuItem>
  41. <MenuItem Header="Отчет"></MenuItem>
  42. </Menu>
  43. <ToolBar>
  44. <Button Name="Undo" Command="{Binding UndoCommand}" ToolTip="Отменить редактирование/создание">
  45. <Image Width="16" Height="16" Source="/Images/undo.png" />
  46. </Button>
  47. <Button Name="Add" Command="{Binding NewCommand}" ToolTip="Добавить">
  48. <Image Width="16" Height="16" Source="/Images/add.png" />
  49. </Button>
  50. <Button Name="Edit" Command="{Binding EditCommand}" ToolTip="Редактировать">
  51. <Image Width="16" Height="16" Source="/Images/edit.png" />
  52. </Button>
  53. <Button Name="Search" Command="{Binding FindCommand}" ToolTip="Поиск">
  54. <Image Width="16" Height="16" Source="/Images/search.png" />
  55. </Button>
  56. <Button Name="Save" Command="{Binding SaveCommand}" ToolTip="Сохранить">
  57. <Image Width="16" Height="16" Source="/Images/save.png" />
  58. </Button>
  59. <Button Name="Delete" Command="{Binding DeleteCommand}" ToolTip="Удалить">
  60. <Image Width="16" Height="16" Source="/Images/delete.png" />
  61. </Button>
  62. </ToolBar>
  63. <Label>Список сотрудников</Label>
  64. <DataGrid
  65. AutoGenerateColumns="False"
  66. ItemsSource="{Binding Employees}"
  67. RowBackground="#ddd"
  68. AlternatingRowBackground="#eee"
  69. CanUserAddRows="False"
  70. CanUserDeleteRows="False"
  71. IsReadOnly="{Binding GridBlocked}"
  72. SelectedItem="{Binding SelectedEmployee}">
  73. <!--Рисуем восклицательный знак если в строке ошибка-->
  74. <DataGrid.RowValidationErrorTemplate>
  75. <ControlTemplate>
  76. <Grid
  77. Margin="0,-2,0,-2"
  78. ToolTip="{Binding
  79. RelativeSource={RelativeSource FindAncestor,
  80. AncestorType={x:Type DataGridRow}},
  81. Path=(Validation.Errors)[0].ErrorContent}">
  82. <Ellipse
  83. StrokeThickness="0"
  84. Fill="Red"
  85. Width="{TemplateBinding FontSize}"
  86. Height="{TemplateBinding FontSize}" />
  87. <TextBlock
  88. Text="!"
  89. FontSize="{TemplateBinding FontSize}"
  90. FontWeight="Bold"
  91. Foreground="White"
  92. HorizontalAlignment="Center" />
  93. </Grid>
  94. </ControlTemplate>
  95. </DataGrid.RowValidationErrorTemplate>
  96. <DataGrid.Columns>
  97. <DataGridTextColumn
  98. Binding="{Binding Path=Surname,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
  99. Header="Фамилия"/>
  100. <DataGridTextColumn
  101. Binding="{Binding Path=Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
  102. Header="Имя"/>
  103. <DataGridTextColumn
  104. Binding="{Binding Path=Patronymic,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
  105. Header="Отчество"/>
  106. <DataGridComboBoxColumn
  107. ItemsSource="{Binding DataContext.AllTitles,Source={x:Reference ProxyElement}}"
  108. DisplayMemberPath="Name"
  109. SelectedValueBinding="{Binding Path=TitleId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
  110. SelectedValuePath="Id"
  111. Header="Должность"/>
  112. <DataGridTemplateColumn
  113. CellTemplate="{StaticResource RegularDateTemplate}"
  114. CellEditingTemplate="{StaticResource EditingDateTemplate}"
  115. Header="Дата рождения" />
  116. <DataGridTextColumn
  117. Binding="{Binding Path=Phone,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
  118. Header="Телефон" />
  119. <DataGridTextColumn
  120. EditingElementStyle="{StaticResource ValidationFail}"
  121. Header="Электронная почта">
  122. <DataGridTextColumn.Binding>
  123. <Binding
  124. Path="Email"
  125. Mode="TwoWay"
  126. UpdateSourceTrigger="PropertyChanged"
  127. ValidatesOnExceptions="True">
  128. <Binding.ValidationRules>
  129. <validation:Email/>
  130. </Binding.ValidationRules>
  131. </Binding>
  132. </DataGridTextColumn.Binding>
  133. </DataGridTextColumn>
  134. </DataGrid.Columns>
  135. </DataGrid>
  136. </StackPanel>
  137. </Page>