using System;
using System.Windows;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var grid = new System.Windows.Controls.Primitives.UniformGrid();
grid.Background = Brushes.LightGreen;
grid.Columns = 1;
grid.Rows = 2;
this.Content = grid;
var jdp1 = new JalaliDatePicker.JalaliDatePickerControl();
jdp1.HorizontalAlignment = HorizontalAlignment.Center;
jdp1.VerticalAlignment = VerticalAlignment.Center;
jdp1.BorderBrush = Brushes.Black;
jdp1.BorderThickness = new Thickness(1);
jdp1.Margin = new Thickness(5);
grid.Children.Add(jdp1);
var jdp2 = new JalaliDatePicker.JalaliDatePickerControl();
jdp2.HorizontalAlignment = HorizontalAlignment.Center;
jdp2.VerticalAlignment = VerticalAlignment.Center;
jdp2.BorderBrush = Brushes.Black;
jdp2.BorderThickness = new Thickness(1);
jdp2.Margin = new Thickness(5);
grid.Children.Add(jdp2);
jdp2.Loaded += OnPickerLoaded;
}
private void OnPickerLoaded(object sender, EventArgs e)
{
var jdp = (JalaliDatePicker.JalaliDatePickerControl)sender;
var border = VisualTreeHelper.GetChild(jdp, 0) as Border;
//var MainGrid = jdp.FindName("MainGrid") as Grid;
var YearBlock = jdp.FindName("YearBlock") as TextBox;
//var MonthBlock = jdp.FindName("MonthBlock") as TextBox;
//var DayOfMonth = jdp.FindName("DayOfMonthBlock") as TextBox;
//var TimeGrid = jdp.FindName("TimeGrid") as Grid;
//var HourBlock = jdp.FindName("HourBlock") as TextBox;
//var MinuteBlock = jdp.FindName("MinuteBlock") as TextBox;
//var DayOfWeekBlock = jdp.FindName("DayOfWeekBlock") as TextBlock;
var PickerBtn = jdp.FindName("PickerBtn") as Button;
var PickerPopup = jdp.FindName("PickerPopup") as System.Windows.Controls.Primitives.Popup;
jdp.Background = Brushes.Pink;
jdp.BorderThickness = new Thickness(2);
SetBorderCorner(jdp, new CornerRadius(5));
SetBorderCorner(PickerBtn, new CornerRadius(0, 5, 5, 0));
YearBlock.Margin = new Thickness(YearBlock.Margin.Left, YearBlock.Margin.Top, YearBlock.Margin.Right - 5, YearBlock.Margin.Bottom);
YearBlock.HorizontalContentAlignment = HorizontalAlignment.Right;
PickerPopup.LayoutTransform = new ScaleTransform(2, 2);
}
private void SetBorderCorner(DependencyObject d, CornerRadius cr)
{
var count = VisualTreeHelper.GetChildrenCount(d);
if (count == 1 && VisualTreeHelper.GetChild(d, 0) is Border border)
{
border.CornerRadius = cr;
}
}
}
Customizing the appearance of a Persian DatePicker (JalaliDatePickerControl)
Reza Jaferi
331
Reputation points
I have a Persian DatePicker
that works properly, and I only want to add to it some public properties to customize its appearance.
What I'd want to add is as follows:
- Background
- BorderBrush
- CornerRadius
I want to be able to access these three attributes directly in XAML
and C#
(Intellisense
).
Additionally, I would like DatePicker
's text to be closer together, as the image above shows.
You can download JalaliDatePickerControl.dll
from here.
I tried to modify the dll using dnSpy
, but I was unsuccessful.
After the aforementioned dll has been recompiled using .NET Framework 4.5
, please upload it to github.com or nuget.org.
1 answer
Sort by: Most helpful
-
gekka 9,586 Reputation points MVP
2023-12-23T03:22:02.3+00:00