<Window x:Class="XLAB.FrpdDirectoryWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Организации и подразделения"
        Height="820"
        Width="1280"
        MinHeight="680"
        MinWidth="1040"
        Loaded="Window_Loaded"
        WindowStartupLocation="CenterOwner">
    <Grid Margin="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="2.2*" />
            <RowDefinition Height="1.5*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0"
                   Margin="0,0,0,12">
            <Button DockPanel.Dock="Right"
                    Width="110"
                    Margin="12,0,0,0"
                    Command="{Binding RefreshCommand}"
                    Content="Обновить" />
            <StackPanel Orientation="Horizontal">
                <TextBlock Margin="0,0,8,0"
                           VerticalAlignment="Center"
                           Text="Поиск " />
                <TextBox Width="360"
                         Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
            </StackPanel>
        </DockPanel>

        <GroupBox Grid.Row="1"
                  Header="Организации и подразделения">
            <DataGrid ItemsSource="{Binding FrpdItems}"
                      SelectedItem="{Binding SelectedFrpd, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить"
                                  Command="{Binding AddFrpdCommand}" />
                        <MenuItem Header="Изменить"
                                  Command="{Binding EditFrpdCommand}" />
                        <MenuItem Header="Удалить"
                                  Command="{Binding DeleteFrpdCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Наименование" Width="*" Binding="{Binding Name}" />
                    <DataGridTextColumn Header="Локальный код" Width="150" Binding="{Binding LocalCode}" />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>

        <GroupBox Grid.Row="2"
                  Margin="0,12,0,0"
                  Header="Виды деятельности подразделения">
            <DataGrid ItemsSource="{Binding FrpdvdItems}"
                      SelectedItem="{Binding SelectedFrpdvd, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      IsReadOnly="True"
                      HeadersVisibility="Column">
                <DataGrid.ContextMenu>
                    <ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
                        <MenuItem Header="Добавить"
                                  Command="{Binding AddFrpdvdCommand}" />
                        <MenuItem Header="Изменить"
                                  Command="{Binding EditFrpdvdCommand}" />
                        <MenuItem Header="Удалить"
                                  Command="{Binding DeleteFrpdvdCommand}" />
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <EventSetter Event="PreviewMouseRightButtonDown"
                                     Handler="DataGridRow_PreviewMouseRightButtonDown" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Вид деятельности" Width="*" Binding="{Binding ActivityName}" />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>

        <TextBlock Grid.Row="3"
                   Margin="0,8,0,0"
                   Foreground="DimGray"
                   Text="{Binding StatusText}" />

        <StackPanel Grid.Row="4"
                    Margin="0,12,0,0"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Width="90"
                    IsCancel="True"
                    Content="Закрыть" />
        </StackPanel>
    </Grid>
</Window>
