DateTimePicker в WPF не меняет дату при нажатии кнопок счетчика - PullRequest
0 голосов
/ 23 января 2020

Я использую расширенную библиотеку Xceed WPF и элемент управления DateTimePicker. Я переопределил стили для элемента управления, чтобы в первую очередь изменить стиль кнопок повтора на стороне. Однако теперь, когда я нажимаю их, они не увеличивают / уменьшают дату-время, как ожидалось. Почему это происходит?

Элемент управления в моем UserControl:

 <xctk:DateTimePicker Grid.Row="1" Style="{StaticResource DateTimePickerStyle}" FontSize="18" ShowDropDownButton="False" IsEnabled="True" Text="{Binding Path=Start}">
        </xctk:DateTimePicker>

DateTimePickerStyle

<Style x:Key="DateTimePickerStyle" TargetType="{x:Type xctk:DateTimePicker}">
        <Setter Property="Background" Value="{StaticResource WhiteColorBrush}"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>

        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="IsEnabled" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type xctk:DateTimePicker}">
                    <Border x:Name="Border"  BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="firstContentColumn" Width="*"/>
                                <ColumnDefinition x:Name="secondContentColumn" Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <TextBox Text="{TemplateBinding Text}" HorizontalContentAlignment="Center" />

                            <!--<ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Text}" IsHitTestVisible="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>-->
                            <Grid x:Name="gridContent" Grid.Column="1" Width="50">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <RepeatButton x:Name="PART_IncreaseButton" Background="{StaticResource NavyBlueBrush}">
                                    <RepeatButton.ContentTemplate>
                                        <DataTemplate>
                                            <Path Data="M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3z" Fill="{StaticResource WhiteColorBrush}" HorizontalAlignment="Center" Height="4" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="7"/>
                                        </DataTemplate>
                                    </RepeatButton.ContentTemplate>
                                </RepeatButton>
                                <RepeatButton x:Name="PART_DecreaseButton" Width="50" Grid.Row="1" Background="{StaticResource NavyBlueBrush}">
                                    <RepeatButton.ContentTemplate>
                                        <DataTemplate>
                                            <Path Data="M0,1C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1z"  Fill="{StaticResource WhiteColorBrush}" HorizontalAlignment="Center" Height="4" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="7"/>
                                        </DataTemplate>
                                    </RepeatButton.ContentTemplate>
                                </RepeatButton>
                            </Grid>
                        </Grid>
                    </Border>
                    <!--<ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlMouseOverBorderKey, TypeInTargetAssembly={x:Type themes:ResourceKeys}}}"/>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlSelectedBorderKey, TypeInTargetAssembly={x:Type themes:ResourceKeys}}}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource {ComponentResourceKey ResourceId=ControlDisabledBackgroundKey, TypeInTargetAssembly={x:Type themes:ResourceKeys}}}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" SourceName="PART_IncreaseButton" Value="False">
                            <Setter Property="ContentTemplate" TargetName="PART_IncreaseButton">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Path Data="M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3z" Focusable="False" Fill="{DynamicResource {ComponentResourceKey ResourceId=GlyphDisabledForegroundKey, TypeInTargetAssembly={x:Type themes:ResourceKeys}}}" HorizontalAlignment="Center" Height="4" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="7"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsEnabled" SourceName="PART_DecreaseButton" Value="False">
                            <Setter Property="ContentTemplate" TargetName="PART_DecreaseButton">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Path Data="M0,1C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1z" Focusable="False" Fill="{DynamicResource {ComponentResourceKey ResourceId=GlyphDisabledForegroundKey, TypeInTargetAssembly={x:Type themes:ResourceKeys}}}" HorizontalAlignment="Center" Height="4" SnapsToDevicePixels="True" VerticalAlignment="Center" Width="7"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="ButtonSpinnerLocation" Value="Left">
                            <Setter Property="Width" TargetName="firstContentColumn" Value="Auto"/>
                            <Setter Property="Width" TargetName="secondContentColumn" Value="*"/>
                            <Setter Property="Grid.Column" TargetName="contentPresenter" Value="1"/>
                            <Setter Property="Grid.Column" TargetName="gridContent" Value="0"/>
                        </Trigger>
                    </ControlTemplate.Triggers>-->
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Как управлять выглядит на экране enter image description here

1 Ответ

0 голосов
/ 24 января 2020

Какую версию элемента управления вы используете? Это известная проблема с xceed DateTimePicker, если дата выбрана с помощью календаря. Они должны войти первым или пока сборщик не потерял фокус. Проблема была исправлена ​​в более поздней версии, чем v3.5

...