我正在创建一个自定义日期选择器,我有一个文本框,在单击后它会打开一个弹出窗口内嵌的日历。我想要做的是改变弹出窗口的大小以显示整个日历,但我无法更改它...... 我已经尝试使用 Height、Width、MinHeight、MinWidth 等属性,但不起作用,弹出窗口仍然显示固定大小。
问题在于我的弹出窗口的父级属性没有被评估,因为它存在表达式问题(根据调试器),所以我确定我的弹出窗口的父级不是主屏幕(比如布局网格)。
我该如何使我的弹出窗口在特定的上下文中打开?
这段代码不是 XAML,只是 C# 代码,看起来像:
问题在于我的弹出窗口的父级属性没有被评估,因为它存在表达式问题(根据调试器),所以我确定我的弹出窗口的父级不是主屏幕(比如布局网格)。
我该如何使我的弹出窗口在特定的上下文中打开?
这段代码不是 XAML,只是 C# 代码,看起来像:
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:类日历只是一个包含多列、超链接按钮和文本块的网格的用户控件,因此没有什么特别之处。
谢谢大家提前;)
干杯 Miloud B.