Modify the DatePicker style in WPF

0

In a Silverlight project I modified the visual design of all the controls by helping with Blend, ComboBox, TextBox, DatePicker, DataGrid, etc. and I saved it in a Dictionary of Resources.xaml and it works very well for the whole project.

Now I'm doing my first project in WPF and I was trying to use the same resource dictionary, but of course several things did not work, for example the functionality of the DataGrid is not correct, I say that UserCanResizeColumns True and does not allow it, I do not know they see the ScrollBars and so ... The fact is that I had to go control by control to try to correct them.

I'm now with the DatePicker and somehow modified the Style of the Calendar, but I can not associate it with the DatePicker to use it, I add an image with a calendar (with modified style) and a DatePicker (with the Calendar with style default) and I add the code that I have in my resource dictionary.

<!-- DatePicker -->
<Style BasedOn="{x:Null}" TargetType="{x:Type DatePicker}">
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="Width" Value="110" />
    <Setter Property="Height" Value="28" />
    <Setter Property="Background" Value="DarkSeaGreen" />
    <Setter Property="BorderBrush" Value="Gray" />
    <Setter Property="BorderThickness" Value="1" />
    <!--<Setter Property="CalendarStyle" Value="{StaticResource DatePickerCalendarStyle}"/>-->
    <Setter Property="DatePicker.CalendarStyle" Value="{StaticResource DatePickerCalendarStyle}"/>
</Style>

<Style x:Key="DatePickerCalendarStyle"
   TargetType="{x:Type Calendar}"
   BasedOn="{StaticResource {x:Type Calendar}}" />

<!-- Calendar -->
<Style  BasedOn="{x:Null}" TargetType="{x:Type Calendar}" >
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="FontStyle" Value="Italic" />
    <Setter Property="FontWeight" Value="Bold" />
    <Setter Property="Background">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFE4EAF0" Offset="0"/>
                <GradientStop Color="#FFECF0F4" Offset="0.16"/>
                <GradientStop Color="#FFFCFCFD" Offset="0.16"/>
                <GradientStop Color="#FFFFFFFF" Offset="1"/>
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
    <Setter Property="BorderBrush">
        <Setter.Value>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

. . Can somebody help me?

    
asked by Cyndy 10.03.2017 в 16:50
source

1 answer

0

DatePicker has its specific Property to assign a style to the Calendar it contains, only declares the DatePicker like this:

<DatePicker 
Style="{DynamicResource MyDatePickerStyle}" 
CalendarStyle="{DynamicResource MyCalendarStyle}" />

Greetings!.

    
answered by 15.03.2017 / 00:03
source