C
C#7mo ago
Mekasu0124

✅ How to use a UserControl inside of a Window?

<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MeksIDE.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MeksIDE.Views.MenuBar;assembly=MeksIDE"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MeksIDE.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="Edimuhtationer">

<Grid RowDefinitions="Auto, *">
<DockPanel Grid.Row="0">
<MenuItem DockPanel.Dock="Top">
<!-- File -->
<uc:FileMenu />
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:MeksIDE.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MeksIDE.Views.MenuBar;assembly=MeksIDE"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MeksIDE.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="Edimuhtationer">

<Grid RowDefinitions="Auto, *">
<DockPanel Grid.Row="0">
<MenuItem DockPanel.Dock="Top">
<!-- File -->
<uc:FileMenu />
So I've moved part of the menu bar at the top of the screen to another UserControl file as my menu bar has a lot of options so I'm breaking it up. As the code above currently sits, I have a blank screen with an arrow in the top-right corner, but nothing else. I used the reference from this stack overflow comment to put in the xmlns:uc="" and the <uc:FileMenu />. Here is the full code for the <uc:FileMenu /> page that is in Views/MenuBar. I'm just not sure what I'm doing wrong. Thanks
4 Replies
Buddy
Buddy7mo ago
ContentControl if you want dynamic controls Or simply define it like normal <yourname:YourCustomControl></yourname:YourCustomControl>
Mekasu0124
Mekasu0124OP7mo ago
so I can remove the xmlns:un line and replace the other with what you just put?
Mekasu0124
Mekasu0124OP7mo ago
I screwed up the project. hold on. I'll brb ok I got it working both ways like this using both cc and uc but now I have the issue of instead of it looking like a regeular menu bar, there's an arrow and the dropdown pops out to the side instead of down like normal becuase of how they're presenting themselves using the uc: or the cc:, its causing them to not have enough room on the menu bar, but if I put all of them back inside of the parent <Menu></Menu> then they'll go back to looking normal. I guess I could just bind the menu to a list in the view model for the main window and have it display that way. idk i'll be back later. I have to go to work. Thanks for your help so far
Want results from more Discord servers?
Add your server