使用弹出窗口的WP7 Silverlight自定义控件

3
我正在创建一个自定义日期选择器,我有一个文本框,在单击后它会打开一个弹出窗口内嵌的日历。我想要做的是改变弹出窗口的大小以显示整个日历,但我无法更改它...... 我已经尝试使用 Height、Width、MinHeight、MinWidth 等属性,但不起作用,弹出窗口仍然显示固定大小。
问题在于我的弹出窗口的父级属性没有被评估,因为它存在表达式问题(根据调试器),所以我确定我的弹出窗口的父级不是主屏幕(比如布局网格)。
我该如何使我的弹出窗口在特定的上下文中打开?
这段代码不是 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.


我可以建议您快速阅读Markdown文档(在编辑问题时右侧有简介)。 - AnthonyWJones
好的。现在关于我的问题呢? - CoolStraw
1个回答

0

弹出控件会自动调整大小以适应其内部内容。例如,如果您将Popup的子元素设置为宽度/高度为100的StackPanel,则弹出窗口将为100x100。

因此,重要的是不要设置弹出窗口的大小,而是设置内部面板的大小。尝试将内容包装到StackPanel中,并在那里分配必要的宽度/高度。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接