开发者

WP7 silverlight custom control using popup

I'm creating a custom datepicker, I have a textbox, once clicked it opens a calendar within a popup. What I want to do is change the size of the popup so it shows my whole calendar, but I can't manage to change it..., I've tried using Height, Width, MinHeight, MinWidth... but it doesn't work, the popup keep showing with a fixed size.

The thing is that my popup's parent property isn't evaluated since it has expression issues (according to debugger), so I'm sure my popup's parent isn't the mai开发者_如何学编程n screen( say layout grid).

How can I for example make my popup open within a specific context ? This part of my code isn't XAML, it's C# code only and it looks like:

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 class Calendar is simply a UserControl that contains a grid with multiple columns, HyperLinkButtons and TextBlocks, so nothing special.

Thank you in advance guys ;)

Cheers Miloud B.


Popup control resizes itself to fit the content inside of it. For example, if you set the child of Popup to be StackPanel with width/height set to 100, the popup will be 100x100.

So it's really important to set the sizes not of your popup, but of your inner panel. Try wrapping your content into the stackpanel and assign necessary width/height there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜