簡體   English   中英

當我嘗試創建具有兩個子元素的StackPanel並將其分配給Flyout時,為什么彈出控件會崩潰?

[英]Why is my flyout crashing when I try to create a StackPanel with two child elements and assign that to a Flyout?

我嘗試在GridView中的網格上右擊時調用Callisto Flyout(最終目標是允許用戶更改值並將其存儲在ApplicationDataContainer中)。 我首先用一個示例創建了一個可以在網上找到的菜單,但是我不想要菜單,因此嘗試將其從菜單更改為帶有TextBlock和TextBox的StackPanel。 這段代碼:

private void ItemView_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
    var flyOut = new Flyout {PlacementTarget = sender as UIElement, Placement = PlacementMode.Mouse};

    var sp = new StackPanel {MinWidth = 240, MinHeight = 80, Orientation = Orientation.Horizontal};

    var tblk = new TextBlock {MinWidth = 60, MinHeight = 72};
    sp.Children.Add(tblk);

    TextBox tb = new TextBox {MinWidth = 120, MinHeight = 72};
    sp.Children.Add(tb);

    flyOut.Content = sp;
    flyOut.IsOpen = true;

    UpdateLayout();        
}

...崩潰並帶我到App.gics中的這一行:

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

順便說一句,我最終可能會將代碼從RightTapped事件移到“魅力設置”中的“適當”位置,但是我認為無論哪種情況都需要解決此問題。

更新

我試圖通過將彈出按鈕從“就地”移動到“ Windows 8設置”面板來走不同的路線:

public ItemsPage()
{
    InitializeComponent();
    SettingsPane.GetForCurrentView().CommandsRequested += OnSettingsPaneCommandRequested;
}

private void ItemView_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
    SettingsPane.Show();
}

private void OnSettingsPaneCommandRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection1Name",
                                                            "Change the name of Section 1", SetAndSaveSectionNames));
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection2Name",
                                                            "Change the name of Section 2", SetAndSaveSectionNames));
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection3Name",
                                                            "Change the name of Section 3", SetAndSaveSectionNames));
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection4Name",
                                                            "Change the name of Section 4", SetAndSaveSectionNames));
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection5Name",
                                                            "Change the name of Section 5", SetAndSaveSectionNames));
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection6Name",
                                                            "Change the name of Section 6", SetAndSaveSectionNames));
}

private void SetAndSaveSectionNames(IUICommand command)
{
    var flyOut = new Flyout(); // flyOut is a Callisto control

    var sp = new StackPanel {MinWidth = 240, MinHeight = 80, Orientation = Orientation.Horizontal};

    var tblk = new TextBlock {MinWidth = 60, MinHeight = 72};
    sp.Children.Add(tblk);
    TextBox tb = new TextBox {MinWidth = 120, MinHeight = 72};
    sp.Children.Add(tb);
    flyOut.Content = sp;
    flyOut.IsOpen = true;

    UpdateLayout();        
}

但是,發生了相同的事情-通過右鍵單擊GridView中的一個網格(ItemView_RightTapped),然后選擇其中一個,可以很好地調用SetAndSaveSectionNames()。

“更改N部分的名稱”文本塊或“設置”面板上的任何文本塊,然后:crasho!

如果一個小伙子想要在“設置”面板中有幾十個設置,那將如何工作-似乎沒有比我添加的六個更多的空間-它會在某個時候萌發一個ViewBox或ScrollBox或其他東西來容納它嗎?

異常可能是NotImplementedException,因為Callisto代碼尚未實現PlacementMode.Mouse選項。 我今天有這個問題。

參見: https : //github.com/timheuer/callisto/blob/master/src/Callisto/Controls/Flyout/Flyout.cs

case PlacementMode.Mouse:
    throw new NotImplementedException("Mouse PlacementMode is not implemented.");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM