2010-10-26 82 views
3

我創建了一個自定義日期選擇器,我有一個文本框,一旦點擊它,它將在彈出窗口中打開一個日曆。 我想要做的是改變彈出窗口的大小,以顯示我的整個日曆,但我無法設法改變它...,我嘗試過使用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:類日曆就是一個包含多列,HyperLinkBut​​tons和的TextBlocks,所以沒有一個網格中的用戶控件特別。

預先感謝您的傢伙;)

乾杯 Miloud B.

+0

我可以建議您快速閱讀Markdown文檔(在編輯問題時右邊有摘要)。 – AnthonyWJones 2010-10-26 10:08:29

+0

好的。 *我的問題*現在呢? – CoolStraw 2010-10-26 11:48:53

回答

1

彈出控制自身的大小,以適應它裏面的內容。例如,如果您將彈出窗口的子項設置爲StackPanel,並將寬度/高度設置爲100,則彈出窗口將爲100x100。

因此,設置不是彈出窗口的大小,而是設置內部面板的大小非常重要。嘗試將您的內容包裝到堆疊面板中並在其中分配必要的寬度/高度。