我需要执行类似以下代码的操作:
<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做到这一点?
发布于 2020-03-15 06:34:48
我不能完全确定您所要求的是什么,但我认为您正在尝试创建一个带有菜单的用户控件,然后在窗口中托管该用户控件的菜单。
像这样的东西应该是有效的:
<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>
https://stackoverflow.com/questions/60637965
复制相似问题