English 中文(简体)
Winui 3 Grid 来自较高构成部分的资源
原标题:Winui 3 Grid Resources not found from higher components

我正试图将某些法典提升到一个层次,以便某些风格能够分享看法。 然而,它用类似于以下信息打破了建筑(取决于我是否只是行文或整个资源字典):

Cannot find a Resource with the Name/Key ImageGridView_ItemTemplate Cannot find a Resource with the Name/Key ImageGridView_ItemContainerStyle

So my original code looks something like the following. And it is working as expected, the item template is being applied and it builds, runs, and looks correct.

  <UserControl
    x:Class="TrackingStation.Views.JobListViewPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:modelsNs="using:ModelsNamespace"
    mc:Ignorable="d">

    <Grid x:Name="RemoveThisTest">
      <Grid Background="{ThemeResource MainBackgroundColourTheme}">
        <Grid.Resources>
          <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
              <ResourceDictionary>
                <DataTemplate x:Key="ImageGridView_ItemTemplate" x:DataType="ModelsNs:CheckInEvent">
                   <!-- The template -->
                </DataTemplate>
              </ResourceDictionary>
            <ResourceDictionary Source="/Resources/CheckoutJobStyles.xaml" />
          </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
      </Grid.Resources>

        <GridView x:Name="WorkItemGridView"
            ItemsSource="{x:Bind ViewModel.SelectedResource.WorkItems, Mode=OneWay}"
            ItemTemplate="{StaticResource ImageGridView_ItemTemplate}"
            ItemContainerStyle="{StaticResource ImageGridView_ItemContainerStyle}"
            ItemsPanel="{StaticResource ImageGridView_ItemsPanelTemplate}"
        />
      </Grid>
    </Grid>
  </UserControl>

Initially it was not in a Resource dictionary etc it was just directly in a resource along with the styles, but I moved them out and merged the dictionaries.

如果我把电网资源移至原电网被nes入的Grid,那么它就会继续工作。

然而,如果我向包含用户控制的电网提升一个等级,那么它就与上述错误信息脱节。 这个没有资源的网格就是:

<UserControl
    x:Class="TrackingStation.Views.CheckoutFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:local="using:TrackingStation.Views"
    mc:Ignorable="d">
    <Grid>
        <local:JobListViewPanel Visibility="{x:Bind ViewModel.IsResourceSelected, Mode=OneWay}" ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
        <local:JobViewPanel Visibility="{x:Bind ViewModel.ShowSingleEventForm, Mode=OneWay}" ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
    </Grid>
</UserControl>

再加上电网资源:

<UserControl
    x:Class="TrackingStation.Views.CheckoutFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:local="using:TrackingStation.Views"
    xmlns:modelsNs="using:ModelsNamespace"
    mc:Ignorable="d">
    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary>
                        <DataTemplate x:Key="ImageGridView_ItemTemplate" x:DataType="modelsNs:CheckInEvent">
                            <!-- the template -->
                        </DataTemplate>
                    </ResourceDictionary>
                    <ResourceDictionary Source="/Resources/CheckoutJobStyles.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Grid.Resources>
        <local:JobListViewPanel Visibility="{x:Bind ViewModel.IsResourceSelected, Mode=OneWay}" ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
        <local:JobViewPanel Visibility="{x:Bind ViewModel.ShowSingleEventForm, Mode=OneWay}" ViewModel="{x:Bind ViewModel, Mode=OneWay}" />
    </Grid>
</UserControl>

在申请的顶端,我有各种各样的其他风格,包括纽托文风格,但这些风格并不重要,只是通用风格。

我100%肯定我做些事情,因此我无需告诉我。 但是,我的理解是,儿童应当有同样的风格,即应用根基确定的纽州风格在整个方案过程中影响到纽芬兰。

Just for completeness, the styles currently are simply:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
    <Style x:Key="ImageGridView_ItemContainerStyle" TargetType="GridViewItem">
        <Setter Property="Background" Value="{ThemeResource SecondaryBackgroundColourTheme}"/>
        <Setter Property="Margin" Value="{StaticResource DefaultMargin}"/>
    </Style>

    <ItemsPanelTemplate x:Key="ImageGridView_ItemsPanelTemplate">
        <ItemsWrapGrid Orientation="Horizontal" HorizontalAlignment="Center"/>
    </ItemsPanelTemplate>
</ResourceDictionary>
问题回答

我也遇到了同样的问题,但是在C++没有明显执行。

下面是一份C#解决方案,具体如下:。 页: 1

CheckoutJobStyles.xaml

<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2CSharp"
    x:Class="App2CSharp.CheckoutJobStyles">

    <Style x:Key="ImageGridView_ItemContainerStyle" TargetType="GridView">
    </Style>

    <ItemsPanelTemplate x:Key="ImageGridView_ItemsPanelTemplate">
        <ItemsWrapGrid Orientation="Horizontal" HorizontalAlignment="Center"/>
    </ItemsPanelTemplate>
</ResourceDictionary>

CheckoutJobStyles.cs

namespace App2CSharp
{
    public partial class CheckoutJobStyles
    {
        public CheckoutJobStyles()
        {
            InitializeComponent();
        }
    }
}

UserControl1.xaml

<!-- Copyright (c) Microsoft Corporation and Contributors. -->
<!-- Licensed under the MIT License. -->

<UserControl
    x:Class="App2CSharp.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2CSharp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid
        Height="32"
        Background="Transparent">
        <Grid.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="CheckoutJobStyles.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock
            Grid.Column="1"
            Margin="5,0,0,0"
            VerticalAlignment="Center"
            Text="{x:Bind Text}" 
            Visibility="{x:Bind l}"/>
        <GridView x:Name="WorkItemGridView"
            ItemContainerStyle="{StaticResource ImageGridView_ItemContainerStyle}"
            ItemsPanel="{StaticResource ImageGridView_ItemsPanelTemplate}"
        />
    </Grid>
</UserControl>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签