Как скрыть значок datepicker в wpf C#?

Я хочу скрыть значок DatePicker по умолчанию:

Как скрыть значок datepicker в wpf C#?

Мне нужно что-то вроде:

 <DatePicker IconVisibality = "False"/>

Я пытался:

Template = "{x:Null}"

но он все скрывает.

Я также пробовал:

Foreground = "{x:Null}"

Кто-нибудь знает?

Два вопроса: зачем и что вы пытались это сделать?

Rafalon 18.12.2018 14:09

Вы что-нибудь пробовали? Потому что такие вопросы имеют большую вероятность быть заданными уже спросил (жаль, удаленный ответ там был бы вам полезен). WPF довольно гибкий, так как вы можете изменить стиль практически для всего.

Sinatr 18.12.2018 14:10

@Rafalon, потому что я открываю диалог через другое событие

BugsFixer 18.12.2018 14:13

@Sinatr нет принятого ответа на первую ссылку, вторая ссылка слишком общая, я ищу конкретный ответ на свой вопрос

BugsFixer 18.12.2018 14:16

Вы искали в Интернете? Как изменить иконку DatePicker / Как удалить образ DatePicker по умолчанию были двумя первыми ссылками быстрого поиска в Google.

Rafalon 18.12.2018 14:20

@Rafalon Вы читали ссылки? первый имеет дело с изменение значок, второй не дает ответа

BugsFixer 18.12.2018 14:33

Я прочитал этот «Вы можете использовать следующий код, если хотите полностью удалить кнопку» во второй ссылке, что наводит меня на мысль, что «следующий код» является ответом. Также "Чтобы удалить / изменить изображение [...] вы можете изменить xaml на "DropDownButtonTemplate"" - похоже, именно на это и ссылалась первая ссылка

Rafalon 18.12.2018 15:02
Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
В JavaScript одним из самых запутанных понятий является поведение ключевого слова "this" в стрелочной и обычной функциях.
Приемы CSS-макетирования - floats и Flexbox
Приемы CSS-макетирования - floats и Flexbox
Здравствуйте, друзья-студенты! Готовы совершенствовать свои навыки веб-дизайна? Сегодня в нашем путешествии мы рассмотрим приемы CSS-верстки - в...
Тестирование функциональных ngrx-эффектов в Angular 16 с помощью Jest
В системе управления состояниями ngrx, совместимой с Angular 16, появились функциональные эффекты. Это здорово и делает код определенно легче для...
Концепция локализации и ее применение в приложениях React ⚡️
Концепция локализации и ее применение в приложениях React ⚡️
Локализация - это процесс адаптации приложения к различным языкам и культурным требованиям. Это позволяет пользователям получить опыт, соответствующий...
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
0
7
1 901
4
Перейти к ответу Данный вопрос помечен как решенный

Ответы 4

Вам необходимо создать собственный шаблон. Вы можете щелкнуть правой кнопкой мыши элемент DatePicker в режиме разработки в Visual Studio или в Blend и выбрать Edit Template-> Edit a Copy, чтобы скопировать шаблон по умолчанию в вашу разметку XAML, а затем удалить из него элемент Button с именем «PART_Button»:

<DatePicker>
    <DatePicker.Style>
        <Style TargetType = "{x:Type DatePicker}">
            <Setter Property = "Foreground" Value = "#FF333333"/>
            <Setter Property = "IsTodayHighlighted" Value = "True"/>
            <Setter Property = "SelectedDateFormat" Value = "Short"/>
            <Setter Property = "Background" Value = "Transparent"/>
            <Setter Property = "Padding" Value = "2"/>
            <Setter Property = "BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint = ".5,0" StartPoint = ".5,1">
                        <GradientStop Color = "#FFA3AEB9" Offset = "0"/>
                        <GradientStop Color = "#FF8399A9" Offset = "0.375"/>
                        <GradientStop Color = "#FF718597" Offset = "0.375"/>
                        <GradientStop Color = "#FF617584" Offset = "1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property = "BorderThickness" Value = "1"/>
            <Setter Property = "HorizontalContentAlignment" Value = "Stretch"/>
            <Setter Property = "Template">
                <Setter.Value>
                    <ControlTemplate TargetType = "{x:Type DatePicker}">
                        <Border BorderBrush = "{TemplateBinding BorderBrush}" BorderThickness = "{TemplateBinding BorderThickness}" Background = "{TemplateBinding Background}" Padding = "{TemplateBinding Padding}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name = "CommonStates">
                                    <VisualState x:Name = "Normal"/>
                                    <VisualState x:Name = "Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration = "0" To = "1" Storyboard.TargetProperty = "Opacity" Storyboard.TargetName = "PART_DisabledVisual"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name = "PART_Root" HorizontalAlignment = "{TemplateBinding HorizontalContentAlignment}" VerticalAlignment = "{TemplateBinding VerticalContentAlignment}">
                                <Grid.Resources>
                                    <SolidColorBrush x:Key = "DisabledBrush" Color = "#A5FFFFFF"/>
                                    <ControlTemplate x:Key = "DropDownButtonTemplate" TargetType = "{x:Type Button}">
                                        <Grid>
                                            <VisualStateManager.VisualStateGroups>
                                                <VisualStateGroup x:Name = "CommonStates">
                                                    <VisualStateGroup.Transitions>
                                                        <VisualTransition GeneratedDuration = "0"/>
                                                        <VisualTransition GeneratedDuration = "0:0:0.1" To = "MouseOver"/>
                                                        <VisualTransition GeneratedDuration = "0:0:0.1" To = "Pressed"/>
                                                    </VisualStateGroup.Transitions>
                                                    <VisualState x:Name = "Normal"/>
                                                    <VisualState x:Name = "MouseOver">
                                                        <Storyboard>
                                                            <ColorAnimation Duration = "0" To = "#FF448DCA" Storyboard.TargetProperty = "(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName = "Background"/>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#7FFFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#CCFFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#F2FFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </VisualState>
                                                    <VisualState x:Name = "Pressed">
                                                        <Storyboard>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName = "Background">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#FF448DCA"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <DoubleAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(UIElement.Opacity)" Storyboard.TargetName = "Highlight">
                                                                <SplineDoubleKeyFrame KeyTime = "0" Value = "1"/>
                                                            </DoubleAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#EAFFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#C6FFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#6BFFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                            <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                                <SplineColorKeyFrame KeyTime = "0" Value = "#F4FFFFFF"/>
                                                            </ColorAnimationUsingKeyFrames>
                                                        </Storyboard>
                                                    </VisualState>
                                                    <VisualState x:Name = "Disabled"/>
                                                </VisualStateGroup>
                                            </VisualStateManager.VisualStateGroups>
                                            <Grid Background = "#11FFFFFF" FlowDirection = "LeftToRight" HorizontalAlignment = "Center" Height = "18" Margin = "0" VerticalAlignment = "Center" Width = "19">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width = "20*"/>
                                                    <ColumnDefinition Width = "20*"/>
                                                    <ColumnDefinition Width = "20*"/>
                                                    <ColumnDefinition Width = "20*"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height = "23*"/>
                                                    <RowDefinition Height = "19*"/>
                                                    <RowDefinition Height = "19*"/>
                                                    <RowDefinition Height = "19*"/>
                                                </Grid.RowDefinitions>
                                                <Border x:Name = "Highlight" BorderBrush = "#FF45D6FA" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = "0,0,1,1" Margin = "-1" Opacity = "0" Grid.Row = "0" Grid.RowSpan = "4"/>
                                                <Border x:Name = "Background" BorderBrush = "#FFFFFFFF" BorderThickness = "1" Background = "#FF1F3B53" Grid.ColumnSpan = "4" CornerRadius = ".5" Margin = "0,-1,0,0" Opacity = "1" Grid.Row = "1" Grid.RowSpan = "3"/>
                                                <Border x:Name = "BackgroundGradient" BorderBrush = "#BF000000" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = ".5" Margin = "0,-1,0,0" Opacity = "1" Grid.Row = "1" Grid.RowSpan = "3">
                                                    <Border.Background>
                                                        <LinearGradientBrush EndPoint = ".7,1" StartPoint = ".7,0">
                                                            <GradientStop Color = "#FFFFFFFF" Offset = "0"/>
                                                            <GradientStop Color = "#F9FFFFFF" Offset = "0.375"/>
                                                            <GradientStop Color = "#E5FFFFFF" Offset = "0.625"/>
                                                            <GradientStop Color = "#C6FFFFFF" Offset = "1"/>
                                                        </LinearGradientBrush>
                                                    </Border.Background>
                                                </Border>
                                                <Rectangle Grid.ColumnSpan = "4" Grid.RowSpan = "1" StrokeThickness = "1">
                                                    <Rectangle.Fill>
                                                        <LinearGradientBrush EndPoint = "0.3,-1.1" StartPoint = "0.46,1.6">
                                                            <GradientStop Color = "#FF4084BD"/>
                                                            <GradientStop Color = "#FFAFCFEA" Offset = "1"/>
                                                        </LinearGradientBrush>
                                                    </Rectangle.Fill>
                                                    <Rectangle.Stroke>
                                                        <LinearGradientBrush EndPoint = "0.48,-1" StartPoint = "0.48,1.25">
                                                            <GradientStop Color = "#FF494949"/>
                                                            <GradientStop Color = "#FF9F9F9F" Offset = "1"/>
                                                        </LinearGradientBrush>
                                                    </Rectangle.Stroke>
                                                </Rectangle>
                                                <Path Grid.ColumnSpan = "4" Grid.Column = "0" Data = "M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z" Fill = "#FF2F2F2F" HorizontalAlignment = "Center" Margin = "4,3,4,3" Grid.Row = "1" Grid.RowSpan = "3" RenderTransformOrigin = "0.5,0.5" Stretch = "Fill" VerticalAlignment = "Center"/>
                                                <Ellipse Grid.ColumnSpan = "4" Fill = "#FFFFFFFF" HorizontalAlignment = "Center" Height = "3" StrokeThickness = "0" VerticalAlignment = "Center" Width = "3"/>
                                                <Border x:Name = "DisabledVisual" BorderBrush = "#B2FFFFFF" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = "0,0,.5,.5" Opacity = "0" Grid.Row = "0" Grid.RowSpan = "4"/>
                                            </Grid>
                                        </Grid>
                                    </ControlTemplate>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width = "*"/>
                                    <ColumnDefinition Width = "Auto"/>
                                </Grid.ColumnDefinitions>
                                <!--<Button x:Name = "PART_Button" Grid.Column = "1" Foreground = "{TemplateBinding Foreground}" Focusable = "False" HorizontalAlignment = "Left" Margin = "3,0,3,0" Grid.Row = "0" Template = "{StaticResource DropDownButtonTemplate}" VerticalAlignment = "Top" Width = "20"/>-->
                                <DatePickerTextBox x:Name = "PART_TextBox" Grid.Column = "0" Focusable = "{TemplateBinding Focusable}" HorizontalContentAlignment = "Stretch" Grid.Row = "0" VerticalContentAlignment = "Stretch"/>
                                <Grid x:Name = "PART_DisabledVisual" Grid.ColumnSpan = "2" Grid.Column = "0" IsHitTestVisible = "False" Opacity = "0" Grid.Row = "0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width = "*"/>
                                        <ColumnDefinition Width = "Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Grid.Column = "0" Fill = "#A5FFFFFF" RadiusY = "1" Grid.Row = "0" RadiusX = "1"/>
                                    <Rectangle Grid.Column = "1" Fill = "#A5FFFFFF" Height = "18" Margin = "3,0,3,0" RadiusY = "1" Grid.Row = "0" RadiusX = "1" Width = "19"/>
                                    <Popup x:Name = "PART_Popup" AllowsTransparency = "True" Placement = "Bottom" PlacementTarget = "{Binding ElementName=PART_TextBox}" StaysOpen = "False"/>
                                </Grid>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding = "{Binding Source = {x:Static SystemParameters.HighContrast}}" Value = "false">
                                <Setter Property = "Foreground" TargetName = "PART_TextBox" Value = "{Binding Foreground, RelativeSource = {RelativeSource TemplatedParent}}"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DatePicker.Style>
</DatePicker>
<Window.Resources>
    <Style x:Key = "DatePickerStyle" TargetType = "{x:Type DatePicker}">
        <Setter Property = "Foreground" Value = "#FF333333"/>
        <Setter Property = "IsTodayHighlighted" Value = "True"/>
        <Setter Property = "SelectedDateFormat" Value = "Short"/>
        <Setter Property = "Background" Value = "Transparent"/>
        <Setter Property = "Padding" Value = "2"/>
        <Setter Property = "BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint = ".5,0" StartPoint = ".5,1">
                    <GradientStop Color = "#FFA3AEB9" Offset = "0"/>
                    <GradientStop Color = "#FF8399A9" Offset = "0.375"/>
                    <GradientStop Color = "#FF718597" Offset = "0.375"/>
                    <GradientStop Color = "#FF617584" Offset = "1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property = "BorderThickness" Value = "1"/>
        <Setter Property = "HorizontalContentAlignment" Value = "Stretch"/>
        <Setter Property = "Template">
            <Setter.Value>
                <ControlTemplate TargetType = "{x:Type DatePicker}">
                    <Border BorderBrush = "{TemplateBinding BorderBrush}" BorderThickness = "{TemplateBinding BorderThickness}" Background = "{TemplateBinding Background}" Padding = "{TemplateBinding Padding}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name = "CommonStates">
                                <VisualState x:Name = "Normal"/>
                                <VisualState x:Name = "Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration = "0" To = "1" Storyboard.TargetProperty = "Opacity" Storyboard.TargetName = "PART_DisabledVisual"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name = "PART_Root" HorizontalAlignment = "{TemplateBinding HorizontalContentAlignment}" VerticalAlignment = "{TemplateBinding VerticalContentAlignment}">
                            <Grid.Resources>
                                <SolidColorBrush x:Key = "DisabledBrush" Color = "#A5FFFFFF"/>
                                <ControlTemplate x:Key = "DropDownButtonTemplate" TargetType = "{x:Type Button}">
                                    <Grid>
                                        <VisualStateManager.VisualStateGroups>
                                            <VisualStateGroup x:Name = "CommonStates">
                                                <VisualStateGroup.Transitions>
                                                    <VisualTransition GeneratedDuration = "0"/>
                                                    <VisualTransition GeneratedDuration = "0:0:0.1" To = "MouseOver"/>
                                                    <VisualTransition GeneratedDuration = "0:0:0.1" To = "Pressed"/>
                                                </VisualStateGroup.Transitions>
                                                <VisualState x:Name = "Normal"/>
                                                <VisualState x:Name = "MouseOver">
                                                    <Storyboard>
                                                        <ColorAnimation Duration = "0" To = "#FF448DCA" Storyboard.TargetProperty = "(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName = "Background"/>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#7FFFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#CCFFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#F2FFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </VisualState>
                                                <VisualState x:Name = "Pressed">
                                                    <Storyboard>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName = "Background">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#FF448DCA"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <DoubleAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(UIElement.Opacity)" Storyboard.TargetName = "Highlight">
                                                            <SplineDoubleKeyFrame KeyTime = "0" Value = "1"/>
                                                        </DoubleAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#EAFFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#C6FFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#6BFFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                        <ColorAnimationUsingKeyFrames BeginTime = "0" Duration = "00:00:00.001" Storyboard.TargetProperty = "(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName = "BackgroundGradient">
                                                            <SplineColorKeyFrame KeyTime = "0" Value = "#F4FFFFFF"/>
                                                        </ColorAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </VisualState>
                                                <VisualState x:Name = "Disabled"/>
                                            </VisualStateGroup>
                                        </VisualStateManager.VisualStateGroups>
                                        <Grid Background = "#11FFFFFF" FlowDirection = "LeftToRight" HorizontalAlignment = "Center" Height = "18" Margin = "0" VerticalAlignment = "Center" Width = "19">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width = "20*"/>
                                                <ColumnDefinition Width = "20*"/>
                                                <ColumnDefinition Width = "20*"/>
                                                <ColumnDefinition Width = "20*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height = "23*"/>
                                                <RowDefinition Height = "19*"/>
                                                <RowDefinition Height = "19*"/>
                                                <RowDefinition Height = "19*"/>
                                            </Grid.RowDefinitions>
                                            <Border x:Name = "Highlight" BorderBrush = "#FF45D6FA" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = "0,0,1,1" Margin = "-1" Opacity = "0" Grid.Row = "0" Grid.RowSpan = "4"/>
                                            <Border x:Name = "Background" BorderBrush = "#FFFFFFFF" BorderThickness = "1" Background = "#FF1F3B53" Grid.ColumnSpan = "4" CornerRadius = ".5" Margin = "0,-1,0,0" Opacity = "1" Grid.Row = "1" Grid.RowSpan = "3"/>
                                            <Border x:Name = "BackgroundGradient" BorderBrush = "#BF000000" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = ".5" Margin = "0,-1,0,0" Opacity = "1" Grid.Row = "1" Grid.RowSpan = "3">
                                                <Border.Background>
                                                    <LinearGradientBrush EndPoint = ".7,1" StartPoint = ".7,0">
                                                        <GradientStop Color = "#FFFFFFFF" Offset = "0"/>
                                                        <GradientStop Color = "#F9FFFFFF" Offset = "0.375"/>
                                                        <GradientStop Color = "#E5FFFFFF" Offset = "0.625"/>
                                                        <GradientStop Color = "#C6FFFFFF" Offset = "1"/>
                                                    </LinearGradientBrush>
                                                </Border.Background>
                                            </Border>
                                            <Rectangle Grid.ColumnSpan = "4" Grid.RowSpan = "1" StrokeThickness = "1">
                                                <Rectangle.Fill>
                                                    <LinearGradientBrush EndPoint = "0.3,-1.1" StartPoint = "0.46,1.6">
                                                        <GradientStop Color = "#FF4084BD"/>
                                                        <GradientStop Color = "#FFAFCFEA" Offset = "1"/>
                                                    </LinearGradientBrush>
                                                </Rectangle.Fill>
                                                <Rectangle.Stroke>
                                                    <LinearGradientBrush EndPoint = "0.48,-1" StartPoint = "0.48,1.25">
                                                        <GradientStop Color = "#FF494949"/>
                                                        <GradientStop Color = "#FF9F9F9F" Offset = "1"/>
                                                    </LinearGradientBrush>
                                                </Rectangle.Stroke>
                                            </Rectangle>
                                            <Path Grid.ColumnSpan = "4" Grid.Column = "0" Data = "M11.426758,8.4305077 L11.749023,8.4305077 L11.749023,16.331387 L10.674805,16.331387 L10.674805,10.299648 L9.0742188,11.298672 L9.0742188,10.294277 C9.4788408,10.090176 9.9094238,9.8090878 10.365967,9.4510155 C10.82251,9.0929432 11.176106,8.7527733 11.426758,8.4305077 z M14.65086,8.4305077 L18.566387,8.4305077 L18.566387,9.3435936 L15.671368,9.3435936 L15.671368,11.255703 C15.936341,11.058764 16.27293,10.960293 16.681133,10.960293 C17.411602,10.960293 17.969301,11.178717 18.354229,11.615566 C18.739157,12.052416 18.931622,12.673672 18.931622,13.479336 C18.931622,15.452317 18.052553,16.438808 16.294415,16.438808 C15.560365,16.438808 14.951641,16.234707 14.468243,15.826504 L14.881817,14.929531 C15.368796,15.326992 15.837872,15.525723 16.289043,15.525723 C17.298809,15.525723 17.803692,14.895514 17.803692,13.635098 C17.803692,12.460618 17.305971,11.873379 16.310528,11.873379 C15.83071,11.873379 15.399232,12.079271 15.016094,12.491055 L14.65086,12.238613 z" Fill = "#FF2F2F2F" HorizontalAlignment = "Center" Margin = "4,3,4,3" Grid.Row = "1" Grid.RowSpan = "3" RenderTransformOrigin = "0.5,0.5" Stretch = "Fill" VerticalAlignment = "Center"/>
                                            <Ellipse Grid.ColumnSpan = "4" Fill = "#FFFFFFFF" HorizontalAlignment = "Center" Height = "3" StrokeThickness = "0" VerticalAlignment = "Center" Width = "3"/>
                                            <Border x:Name = "DisabledVisual" BorderBrush = "#B2FFFFFF" BorderThickness = "1" Grid.ColumnSpan = "4" CornerRadius = "0,0,.5,.5" Opacity = "0" Grid.Row = "0" Grid.RowSpan = "4"/>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width = "*"/>
                                <ColumnDefinition Width = "Auto"/>
                            </Grid.ColumnDefinitions>
                            <!--This is Button Templete-->
                            <Button x:Name = "PART_Button" Grid.Column = "1" Foreground = "{TemplateBinding Foreground}" Focusable = "False" HorizontalAlignment = "Left" Margin = "3,0,3,0" Grid.Row = "0"  VerticalAlignment = "Top" Width = "20"/>
                            <!--...-->
                            <DatePickerTextBox x:Name = "PART_TextBox" Grid.Column = "0" Foreground = "{TemplateBinding Foreground}" Focusable = "{TemplateBinding Focusable}" HorizontalContentAlignment = "Stretch" Grid.Row = "0" VerticalContentAlignment = "Stretch"/>
                            <Grid x:Name = "PART_DisabledVisual" Grid.ColumnSpan = "2" Grid.Column = "0" IsHitTestVisible = "False" Opacity = "0" Grid.Row = "0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width = "*"/>
                                    <ColumnDefinition Width = "Auto"/>
                                </Grid.ColumnDefinitions>
                                <Rectangle Grid.Column = "0" Fill = "#A5FFFFFF" RadiusY = "1" Grid.Row = "0" RadiusX = "1"/>
                                <Rectangle Grid.Column = "1" Fill = "#A5FFFFFF" Height = "18" Margin = "3,0,3,0" RadiusY = "1" Grid.Row = "0" RadiusX = "1" Width = "19"/>
                                <Popup x:Name = "PART_Popup" AllowsTransparency = "True" Placement = "Bottom" PlacementTarget = "{Binding ElementName=PART_TextBox}" StaysOpen = "False"/>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <DatePicker Width = "150" Height = "26" Style = "{StaticResource DatePickerStyle}"/>
</Grid>

Вы можете добавить несколько слов, объясняющих ключевые моменты и детали вашего ответа: как это работает и почему. Комментарий xaml едва виден внутри такого длинного фрагмента кода.

Sinatr 18.12.2018 15:09

Просто замените свой шаблон другим стилем (например, этим) и укажите его с помощью StaticResource на свой DatePicker.

<Style x:Key = "WithoutButtonPickerStyle" TargetType = "{x:Type DatePicker}">
    <Setter Property = "Template">
          <Setter.Value>
              <ControlTemplate TargetType = "{x:Type DatePicker}">
                     <Grid x:Name = "PART_Root" HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch">
                         <DatePickerTextBox x:Name = "PART_TextBox">...</DatePickerTextBox>
                         <Button x:Name = "PART_Button" Visibility = "Hidden"/>
                     </Grid>
               </ControlTemplate>
           </Setter.Value>
     </Setter>
</Style>
Ответ принят как подходящий

Более легкий способ - создать собственный элемент управления.

public class CustomDatePicker:DatePicker
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        if (Template.FindName("PART_Button", this) is Button button)
        {
            button.Visibility = System.Windows.Visibility.Hidden;
        }
    }
} 

А затем использовать его в Xaml

<local:CustomDatePicker   />

Здорово! Спасибо! Я написал Visibility.Collaped вместо Visibility.Hidden:-)

Basssprosse 22.06.2021 10:43

Другие вопросы по теме