I create a custom datepicker, I have a text box, after clicking it, the calendar opens in a popup window. What I want to do is resize the popup to show my entire calendar, but I can’t resize it ... I tried using Height, Width, MinHeight, MinWidth ... but it is not. It doesn’t work, the popup is displayed with a fixed size.
The fact is that my parent property popup is not evaluated, since it has problems with expression (according to the debugger), so I am sure that my pop-up parent is not the main screen (for example, the layout grid).
How can I, for example, open a popup in a specific context? This part of my code is not XAML, it is only C # code and looks like this:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
namespace CalendarBranch.components
{
public class wpDatePicker:TextBox
{
private CalendarPopup calendar;
private Popup popup;
public wpDatePicker()
{
this.calendar = new CalendarPopup();
this.popup = new Popup();
this.popup.Child = this.calendar;
this.popup.Margin = new Thickness(0);
this.MouseLeftButtonUp += new MouseButtonEventHandler(wpDatePicker_MouseLeftButtonUp);
this.calendar.onDateSelect += new EventHandler(onDateSelected);
this.IsReadOnly = true;
}
protected void wpDatePicker_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
this.popup.Height = this.calendar.Height;
this.popup.Width = this.calendar.Width;
this.popup.HorizontalAlignment = HorizontalAlignment.Center;
this.popup.VerticalAlignment = VerticalAlignment.Center;
this.popup.HorizontalOffset = 0;
this.popup.VerticalOffset = 0;
this.popup.MinHeight = this.calendar.Height;
this.popup.MinWidth = this.calendar.Width;
this.popup.IsOpen = true;
}
private void onDateSelected(Object sender, EventArgs ea) {
this.Text = this.calendar.SelectedValue.ToShortDateString();
this.popup.IsOpen = false;
}
}
}
PS: the Calendar class is just a UserControl that contains a grid with multiple columns, HyperLinkButtons and TextBlocks, so nothing special.
Thanks in advance guys;)
Cheers Miloud B.
source
share