1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| <Window x:Class="WpfCalendarT_BA_78.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfCalendarT_BA_78"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
Title="Material Design WPF" Height="350" Width="700"
Style="{StaticResource MaterialDesignWindow}" Cursor="">
<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="Padding" Value="2" />
<Setter Property="BorderThickness" Value="0.5" />
<Setter Property="BorderBrush" Value="#FF333333" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<!-- Style du calendrier personnalisé -->
<Setter Property="CalendarStyle" Value="{DynamicResource {x:Type Calendar}}" />
<!-- Nouveau ControlTemplate personnalisé -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePicker}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
CornerRadius="4" >
<Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Cursor="">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Zone de texte pour la date -->
<DatePickerTextBox x:Name="PART_TextBox" Grid.Column="0" VerticalContentAlignment="Center" Padding="5,0,0,0" Margin="1"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<!-- Bouton pour ouvrir le calendrier -->
<Button x:Name="PART_Button" Grid.Column="1" Cursor="Hand" Background="White" VerticalContentAlignment="Top" >
<Viewbox x:Name="viewbox" Width="16" Height="16" Cursor="" >
<Canvas Width="16" Height="16" >
<Path Name="Arrow" Data="M3,6 L5,6 L5,4 L7,4 L7,6 L17,6 L17,4 L19,4 L19,6 L21,6 L21,20 L3,20 Z" Fill="#F7C23E" />
</Canvas>
</Viewbox>
</Button>
<!-- Fenêtre contextuelle du calendrier -->
<Popup x:Name="PART_Popup" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<Calendar x:Name="PART_Calendar"
SelectedDate="{Binding SelectedDate, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Cursor=""
Style="{StaticResource MaterialDesignCalendarPortrait}"/>
</Border>
</Popup>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Background="{DynamicResource MaterialDesignPaper}" Margin="0,0,-121,0">
<DatePicker x:Name="Dp" VerticalAlignment="Top" HorizontalAlignment="Left" Width="200" Margin="200,200,0,0" Style="{StaticResource DatePickerStyle}" />
</Grid>
</Window> |
Partager