0

我试图在 GridView 中右键点击网格时调用 Callisto Flyout(最终目标是允许用户更改值并将其存储在 ApplicationDataContainer 中)。我首先尝试了一个示例,该示例创建了一个我在网上找到的菜单——它有效,但我不想要一个菜单​​。所以我尝试将它从一个菜单更改为一个 StackPanel,上面有一个 TextBlock 和一个 TextBox。这段代码,虽然:

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 事件移到 Charms Settings 中它可能“正确”的位置,但我认为无论哪种情况都需要解决这个问题。

更新

我试图通过将弹出窗口从“就地”移动到 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 或其他东西来适应这个吗?

4

1 回答 1

1

异常可能是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.");
于 2013-09-05T06:51:31.327 回答