Xaml::Controls::MenuBar crashes
allan2 opened this issue ยท 9 comments
I'm trying to add a menu bar to the simple window example.
It crashes with exit code 0xc000027b.
To get access to Append()
on Children
, I added Microsoft::UI::Xaml::Controls::UIElementCollection
to windows::build!
.
let menu_bar = MenuBar::new()?;
let stack_panel = StackPanel::new()?;
stack_panel.Children()?.Append(&menu_bar)?;
stack_panel.Children()?.Append(&button)?;
window.SetContent(&stack_panel)?;
Unless you have reason to believe this issue is specific to the Windows crate, you may want to raise API-specific issues on the WinUI repo:
Appears to be a WinUI bug. (Unpackaged apps aren't officially supported until ~Q4 2021).
In this specific case, MUX is attempting to load Microsoft.UI.Xaml/Themes/generic.xaml
to style the MenuBar you just added and fast failing because we're not packaged.
Cannot load DefaultStyleResourceUri 'ms-appx:///Microsoft.UI.Xaml/Themes/generic.xaml' for TargetType
'Microsoft.UI.Xaml.Controls.MenuBar' in assembly 'Unknown'.
(7d10.8648): Unknown exception - code c000027b
# Call Site
00 KERNELBASE!RaiseFailFastException
01 combase!RoFailFastWithErrorContextInternal2
02 Microsoft_UI_Xaml!DirectUI::DefaultStyles::GetDefaultStyleByTypeName
03 Microsoft_UI_Xaml!DirectUI::DefaultStyles::GetDefaultStyleByKey
04 Microsoft_UI_Xaml!AgCoreCallbacks::GetBuiltInStyle
05 Microsoft_UI_Xaml!CControl::GetBuiltInStyle
[...]
I'll dig into this and figure out how this will be handled for unpackaged apps going forward.
Thanks. Should I open this issue on microsoft-ui-xaml?
I'm also getting this error when I try to add MenuBarItemFlyout to MenuBarItem.
let menu_bar = MenuBar::new()?;
let file_menu = MenuBarItem::new()?;
let file_menu_exit = MenuBarItemFlyout::new()?;
file_menu.Items()?.Append(file_menu_exit)?; // error is here
menu_bar.Items()?.Append(file_menu)?;
error[E0277]: the trait bound `MenuBarItemFlyout: IntoParam<'_, MenuFlyoutItemBase>` is not satisfied
--> src\main.rs:61:35
|
61 | file_menu.Items()?.Append(file_menu_exit)?;
| ^^^^^^^^^^^^^^ the trait `IntoParam<'_, MenuFlyoutItemBase>` is not implemented for `MenuBarItemFlyout`
|
= help: the following implementations were found:
<&'a MenuBarItemFlyout as IntoParam<'a, DependencyObject>>
<&'a MenuBarItemFlyout as IntoParam<'a, FlyoutBase>>
<&'a MenuBarItemFlyout as IntoParam<'a, IInspectable>>
<&'a MenuBarItemFlyout as IntoParam<'a, MenuFlyout>>
and 4 others
error: aborting due to previous error
@allan2 I opened that first issue under Related on your behalf. I'll poke and prod folks about this, so nothing else needed from you at this time. ๐
Regarding your other question:
Items()
returns a IVector<MenuFlyoutItemBase>>
. Reviewing the docs, it appears this container can hold the following objects:
- MenuFlyoutItem
- MenuFlyoutSeparator
- MenuFlyoutSubItem
let menu_bar = MenuBar::new()?;
let file_menu = MenuBarItem::new()?;
- let file_menu_exit = MenuBarItemFlyout::new()?;
+ let file_menu_exit = MenuFlyoutItem::new()?;
+ file_menu_exit.SetText("Exit")?;
file_menu.Items()?.Append(file_menu_exit)?; // error is here
menu_bar.Items()?.Append(file_menu)?;
This will compile (after you update your build macro) but it won't run for the same reasons above.
If you have any further general dev questions, I ask that you hold off from posting them in this issue. Let me get GitHub Discussions wired up.
@riverar You're rad!
I even looked in the XAML controls gallery but I still flubbed it somehow.
Meet you in the Discussions when you're ready!
@allan2 Decided against Discussions for now, as we don't want to create a blackhole this early. Feel free to continue here (if related) or open new issues in the meantime.
Any value in keeping this issue open? Doesn't look like there's any actionable work here for the windows-app
crate.
@kennykerr Not really. We're blocked until WinUI 3 puts out a release that supports unpackaged scenarios. Then we'll have some work to wire that up, etc.