【问题标题】:Avalonia Ui putting a UserControl inside anotherAvalonia Ui 将 UserControl 放入另一个
【发布时间】:2020-03-11 14:07:57
【问题描述】:

我需要执行以下代码:

<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 可以做到这一点吗?

【问题讨论】:

    标签: c# wpf avaloniaui avalonia


    【解决方案1】:

    不完全确定,您要的是什么,但我认为您正在尝试在内部创建一个带有菜单的用户控件,然后在窗口中创建一个带有菜单的用户控件。

    这样的事情应该可以工作:

    <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>
    

    result window

    【讨论】:

      猜你喜欢
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多