我创建了一个自定义日期选择器,我有一个文本框,一旦点击它,它将在弹出窗口中打开一个日历。 我想要做的是改变弹出窗口的大小,以显示我的整个日历,但我无法设法改变它...,我尝试过使用Height,Width,MinHeight,MinWidth ...但它不起作用,弹出窗口会以固定大小显示。WP7 Silverlight自定义控件使用弹出框
问题是我的popup的父属性没有被评估,因为它有表达式问题(根据调试器),所以我确定我的弹出框的父母不是主屏幕(比如布局网格)。
我怎样才能让我的弹出窗口在特定的上下文中打开? 我的代码这部分是不是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:类日历就是一个包含多列,HyperLinkButtons和的TextBlocks,所以没有一个网格中的用户控件特别。
预先感谢您的家伙;)
干杯 Miloud B.
我可以建议您快速阅读Markdown文档(在编辑问题时右边有摘要)。 – AnthonyWJones 2010-10-26 10:08:29
好的。 *我的问题*现在呢? – CoolStraw 2010-10-26 11:48:53