首页 > 解决方案 > 即使将内容网格命名为“__catelInnerWrapper”,Catel 也会在视图模型网格中包装用户控件内容

问题描述

我在 Catel 中为 Catel 用户控件手动创建视图模型网格时遇到问题。该文档暗示,通过将内容网格命名为“__catelInnerWrapper”,ViewModelWrapperService 不会用另一个网格包装内容,而是使用我的网格。我想这样做是出于视觉状态管理的目的。使用 Snoopwpf 我可以看到用户控件仍在被包装。
https://i.imgur.com/teSu9La.png

我尝试使用 Catel 5.8.0 和 5.9.0 beta 0 创建一个新的 Catel 项目模板,使用 .NET 4.6.1 和主窗口中的单个用户控件来测试简化的应用程序并看到相同的行为。

<catel:UserControl x:Class="CatelTest.Views.MyUserControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"           
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:catel="http://schemas.catelproject.com">

    <Grid x:Name="__catelInnerWrapper">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>      
        <Label Grid.Row="0" Content="{Binding Title}" />
        <Label Grid.Row="1" Content="My User Control" />
    </Grid> 
</catel:UserControl>    

在逐步执行 ViewModelWrappingService.xaml.cs 代码时,似乎用户控件内容名称属性始终解析为 null,因此与 InnerWrapperName 不匹配。你知道为什么会发生这种情况吗?谢谢

标签: catel

解决方案


查看源代码时,您正在做正确的事情。如果您 100% 确定:

  1. 您正在使用正确的构建(例如完全重建的应用程序,而不是错误的配置)
  2. 窥探是正确的

然后请在https://github.com/catel/catel/报告一个问题(最少重现),我们将确保它会在 Catel 5.9 中得到修复(目前处于测试阶段,即将发布,但我们将等待这个一)。


推荐阅读