简体   繁体   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?

I'm trying to invoke a Callisto Flyout when right-tapping on a grid in a GridView (the ultimate goal is to allow the user to change a value and store that in an ApplicationDataContainer). 我尝试在GridView中的网格上右击时调用Callisto Flyout(最终目标是允许用户更改值并将其存储在ApplicationDataContainer中)。 I first tried it with a sample that creates a menu that I found online -- that works, but I don't want a menu.So I tried changing it up from a menu to a StackPanel with a TextBlock and a TextBox on it. 我首先用一个示例创建了一个可以在网上找到的菜单,但是我不想要菜单,因此尝试将其从菜单更改为带有TextBlock和TextBox的StackPanel。 This code, though: 这段代码:

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();        
}

...crashes and takes me to this line in App.gics: ...崩溃并带我到App.gics中的这一行:

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

BTW, I may eventually move this code from the RightTapped event to be in its presumably "proper" place in the Charms Settings, but I reckon this problem needs to be solved in either case. 顺便说一句,我最终可能会将代码从RightTapped事件移到“魅力设置”中的“适当”位置,但是我认为无论哪种情况都需要解决此问题。

UPDATE 更新

I tried to go a different route with this by moving the flyout from "in place" to the Windows 8 Settings panel: 我试图通过将弹出按钮从“就地”移动到“ 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();        
}

However, the same thing happens - I can get to the call to SetAndSaveSectionNames() just fine by right-clicking one of the grids in my GridView (ItemView_RightTapped), and then selecting one of 但是,发生了相同的事情-通过右键单击GridView中的一个网格(ItemView_RightTapped),然后选择其中一个,可以很好地调用SetAndSaveSectionNames()。

the "Change the name of Section N" TextBlocks or whatever they are on the Settings panel, but then: crasho! “更改N部分的名称”文本块或“设置”面板上的任何文本块,然后:crasho!

If a fella wants to have dozens of settings in the Settings panel, how will that work - it seems there's not room for much more than the six I added - will it sprout a ViewBox or ScrollBox or something at some point to accommodate this? 如果一个小伙子想要在“设置”面板中有几十个设置,那将如何工作-似乎没有比我添加的六个更多的空间-它会在某个时候萌发一个ViewBox或ScrollBox或其他东西来容纳它吗?

The exception is probably NotImplementedException because the Callisto code has not implemented the PlacementMode.Mouse option. 异常可能是NotImplementedException,因为Callisto代码尚未实现PlacementMode.Mouse选项。 I had this issue today. 我今天有这个问题。

See: https://github.com/timheuer/callisto/blob/master/src/Callisto/Controls/Flyout/Flyout.cs 参见: 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.

相关问题 单击帮助图标时创建提示弹出 - Create Hints flyout when clicking on help icon 如何在WPF中创建弹出面板 - how to create a flyout panel in WPF 为什么我无法在 windows - .NET MAUI 上打开带有 ImageButton 的弹出窗口 - why I can't open a flyout with a ImageButton on windows - .NET MAUI 在弹出窗口打开时(如在MS Office应用程序中)按下键/字母时,如何触发弹出菜单项? - How do I trigger flyout menu item when a key/letter is pressed while the flyout is open like in MS Office apps? 当我将我的内容视图作为孩子添加到堆栈面板时,我的滚动视图跳跃 - My scrollview jumping when I add my contentview as a child to stackpanel 我可以对Flyout飞出做出响应,然后以编程方式为其控件分配值吗? - Can I respond to a Flyout flying out and then assign values to its controls programatically? 在Stackpanel中排列子元素 - Arranging Child elements in stackpanel 从 Flyout XAML 中的按钮访问 Flyout - Access Flyout from button inside Flyout XAML Windows Phone 8.1-如何创建弹出窗口(?)并使屏幕的其余部分变暗? - Windows Phone 8.1 - How to create a flyout (?) and dim the rest of the screen? WPF:是否可以使用MahApps.Metro在可滚动窗口上创建弹出窗口? - WPF: Is it Possible to create Flyout on scrollable window using MahApps.Metro?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM