C# Avalonia Ui将用户控件放在另一个用户控件中
我需要执行以下类似代码的操作:C# Avalonia Ui将用户控件放在另一个用户控件中,c#,wpf,avaloniaui,avalonia,C#,Wpf,Avaloniaui,Avalonia,我需要执行以下类似代码的操作: <UserControl x:Class="MyApp.Views.UserControls.UCMainControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
<UserControl x:Class="MyApp.Views.UserControls.UCMainControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxnav="http://schemas.devexpress.com/winfx/2008/xaml/navigation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MyApp.Views.UserControls">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="140"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="220"/>
</Grid.ColumnDefinitions>
<Controls:UCMenuPrincipal x:Name="MenuPrincipalcontrol" Grid.Row="0"/>
</Grid>
在这段代码中,我需要在另一个UserControl上放置一个菜单,但是该菜单位于另一个UserControl中(但是,它可以是任何东西)
当代码是在正常的WPF我可以这样做。Avalonia有可能做到这一点吗?不完全确定您的要求,但我认为您正在尝试使用一个包含菜单的用户控件,然后使用一个菜单托管此用户控件的窗口 像这样的方法应该会奏效:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyApp.ViewModels;assembly=MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MyApp.Views.UserControls;assembly=MyApp"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MyApp.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="MyApp">
<uc:UCMainControl/>
</Window>
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="clr-namespace:MyApp.Views.UserControls;assembly=MyApp"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MyApp.Views.UserControls.UCMainControl">
<Grid RowDefinitions="Auto,Auto,*,140" ColumnDefinitions="Auto,*,220">
<uc:UCMenuPrincipal x:Name="MenuPrincipalcontrol" Grid.Row="0"/>
</Grid>
</UserControl>
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MyApp.Views.UserControls.UCMenuPrincipal">
<Menu Background="AliceBlue">
<MenuItem Header="File"/>
<MenuItem Header="Edit"/>
<MenuItem Header="Help"/>
</Menu>
</UserControl>