c# - Avalonia Ui 将 UserControl 放入另一个
问题描述
我需要执行以下代码:
<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>
推荐阅读
- r - 热图(geom_tile)的调整?
- c# - 如何在流利的NHibernate中创建外键关系而不持有对父实体的引用
- arduino - 带有 Esp32 w5500 以太网模块的软件在 Mqtt 存在重新连接问题
- mysql - 预期输入结束,但在连接中使用 UNNEST 时获得关键字“ON”(bigQuery)
- spring-boot - Spring websocket jwt身份验证
- d3.js - 将 Flash 坐标转换为 GeoJSON
- angular - 架构验证失败并出现以下错误:数据路径“”不能有其他属性(inlineStyleLanguage)
- docker - 如何让 docker 在作为容器的 Jenkins 节点中运行?
- python - skcuda.linalg.PCA 的 fit_transform 抛出错误
- gnu-screen - 当我 ctr-c 数字时,屏幕显示“复制模式已中止”