<ui:ContextAwareControl x:Class="Valg.EVA.Skanning.JobManagement.Startup.UI.PollingDistrict.PollingDistrictsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:ui="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI"
             xmlns:pollingDistrict="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.PollingDistrict"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:filter="clr-namespace:Valg.EVA.Skanning.JobManagement.Startup.UI.Filter"
             HasOnlyOnePollingDistrict="{Binding HasOnlyOnePollingDistrict}"
            mc:Ignorable="d"
            x:Name="PollingDistrictsControl"
            d:DataContext="{d:DesignInstance d:Type=pollingDistrict:PollingDistrictsViewModel}"
                        IsTabStop="False">
    <ui:ContextAwareControl.InputBindings>
        <KeyBinding Key="F5"
                    Command="{Binding RefreshCommand}" />
    </ui:ContextAwareControl.InputBindings>
    <StackPanel>
        <filter:FilterView
            DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=FilterViewModel}"
            VotingCategoryType="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=VotingCategoryType}"
            Visibility="{Binding DataContext.HasMoreThan1PollingDistrict, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pollingDistrict:PollingDistrictsView}}, Converter={StaticResource BooleanToVisibilityConverter}}" />
        <ItemsControl IsTabStop="False" ItemsSource="{Binding PollingDistricts}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <ui:ContextAwareControl IsTabStop="False" PollingDistrict="{Binding}" VotingCategoryType="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ui:ContextAwareControl}}, Path=VotingCategoryType}">
                            <pollingDistrict:PollingDistrictView DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=PollingDistrictViewModel}"
                                    HasOnlyOnePollingDistrict="{Binding ElementName=PollingDistrictsControl, Path=HasOnlyOnePollingDistrict}" />
                        </ui:ContextAwareControl>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.Template>
                <ControlTemplate>
                    <StackPanel>
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                    </StackPanel>
                </ControlTemplate>
            </ItemsControl.Template>
        </ItemsControl>
    </StackPanel>
</ui:ContextAwareControl>
