Skip to content

error CS0117: NavigationViewItem does not contain a definition for UpdateResourceBindings #7279

Open

Description

@boexler

Current behavior

I have a page with two DataTemplates.

However, I get the following error message:

D:..\HtSuiteUno.Wasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainShellView_627ecb4bb5e786243ce503652800ca11.cs(371,5,371,35): error CS0103: Der Name "NavigationViewItemDataTemplate" ist im aktuellen Kontext nicht vorhanden.

D:..\HtSuiteUno.Wasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainShellView_627ecb4bb5e786243ce503652800ca11.cs(372,5,372,42): error CS0103: Der Name "NavigationViewItemProfileDataTemplate" ist im aktuellen Kontext nicht vorhanden.

If I start the project as an UWP app, I don't get any errors and everything works as expected.

<Page
  x:Class="HtSuiteUno.Views.Shell.MainShellView"
  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:viewManagement="using:Windows.UI.ViewManagement"
  xmlns:clock="using:HtSuiteUno.UserControls.Clock"
  xmlns:shell="using:HtSuiteUno.ViewModels.Shell"
  xmlns:common="using:HtSuiteUno.Infrastructure.Common"
  mc:Ignorable="d"
  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  <Page.Resources>
    <DataTemplate x:Name="NavigationViewItemDataTemplate" x:DataType="shell:NavigationItem">
      <Grid Height="40">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="32" />
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <FontIcon Glyph="{x:Bind Glyph}"
                  HorizontalAlignment="Left"
                  FontSize="16" />
        <TextBlock Grid.Column="1"
                   Text="{x:Bind Label}"
                   VerticalAlignment="Center" />
        <TextBlock Grid.Column="2"
                   VerticalAlignment="Center"
                   Margin="12,0"
                   Text="{x:Bind Badge, Mode=OneWay}"
                   Foreground="{StaticResource Error}" />
      </Grid>
    </DataTemplate>

    <DataTemplate x:Name="NavigationViewItemProfileDataTemplate" x:DataType="common:UserInfo">
      <Grid Width="300" Height="40">
        <Grid IsTapEnabled="False">
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="32" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="4" />
          </Grid.ColumnDefinitions>
          <Viewbox Margin="-2,9,0,9" HorizontalAlignment="Left">
            <PersonPicture ProfilePicture="{x:Bind PictureSource, Converter={StaticResource ObjectToImageConverter}}"
                           DisplayName="{x:Bind DisplayName}" />
          </Viewbox>
          <TextBlock Grid.Column="1" Text="{x:Bind DisplayName}" VerticalAlignment="Center" />
        </Grid>
        <Button Margin="-4,0,0,0" BorderThickness="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                Opacity="0" Click="OnLogoff" />
      </Grid>
    </DataTemplate>
  </Page.Resources>

  <Grid>
    <NavigationView
      x:Name="navigationView"
      Grid.Row="1"
      Style="{StaticResource BackButtonNavigationViewStyle}"
      Background="#EBEBEB"
      MenuItemsSource="{x:Bind ViewModel.Items}"
      MenuItemTemplate="{StaticResource NavigationViewItemDataTemplate}"
      SelectedItem="{x:Bind ViewModel.SelectedItem, Mode=TwoWay}"
      SelectionChanged="OnSelectionChanged"
      IsPaneOpen="{x:Bind ViewModel.IsPaneOpen, Mode=TwoWay}"
      AlwaysShowHeader="False"
      IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">

      <Grid>
        <Frame x:Name="frame">
          <Frame.ContentTransitions>
            <TransitionCollection>
              <NavigationThemeTransition />
            </TransitionCollection>
          </Frame.ContentTransitions>
        </Frame>
      </Grid>

      <NavigationView.PaneFooter>
        <NavigationViewItem ContentTemplate="{StaticResource NavigationViewItemProfileDataTemplate}"
                            Content="{x:Bind ViewModel.UserInfo, Mode=OneWay}" />
      </NavigationView.PaneFooter>
    </NavigationView>
  </Grid>
</Page>

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

No response

Affected platforms

WebAssembly, Windows

IDE

Visual Studio 2019

IDE version

16.11.3

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    difficulty/tbd
    kind/bug
    triage/untriaged
    on Oct 5, 2021
  2. Youssef1313 commented on Oct 5, 2021

    @Youssef1313
    Member

    Simpler repro:

    <Page
        x:Class="App46.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:App46"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Page.Resources>
            <DataTemplate x:Name="MyDataTemplate" x:DataType="ListViewItem">
                <Grid />
            </DataTemplate>
    
        </Page.Resources>
    
        <Grid />
    </Page>
    

    The generated code for that:

    // <autogenerated />
    #pragma warning disable 618  // Ignore obsolete members warnings
    #pragma warning disable 105  // Ignore duplicate namespaces
    #pragma warning disable 1591 // Ignore missing XML comment warnings
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using Uno.UI;
    using Uno.UI.Xaml;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Documents;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Media.Animation;
    using Windows.UI.Xaml.Shapes;
    using Windows.UI.Text;
    using Uno.Extensions;
    using Uno;
    using Uno.UI.Helpers.Xaml;
    using App46.Skia.Gtk;
    
    #if __ANDROID__
    using _View = Android.Views.View;
    #elif __IOS__
    using _View = UIKit.UIView;
    #elif __MACOS__
    using _View = AppKit.NSView;
    #elif UNO_REFERENCE_API || NET461
    using _View = Windows.UI.Xaml.UIElement;
    #endif
    
    namespace App46
    {
    	partial class MainPage : Windows.UI.Xaml.Controls.Page
    	{
    		private void InitializeComponent()
    		{
    			var nameScope = new global::Windows.UI.Xaml.NameScope();
    			NameScope.SetNameScope(this, nameScope);
    			base.IsParsing = true;
    			Resources[
    			"MyDataTemplate"
    			] = 
    			new global::Windows.UI.Xaml.DataTemplate(this , __owner => 			new _MainPage_79092a156bed07fd24ba9e19c71a1e65_App46MainPageSC0().Build(__owner)
    			)			;
    			// Source ..\..\..\..\App46.Shared\MainPage.xaml (Line 1:2)
    			base.Content = 
    			new global::Windows.UI.Xaml.Controls.Grid
    			{
    				IsParsing = true,
    				// Source ..\..\..\..\App46.Shared\MainPage.xaml (Line 17:6)
    			}
    			.MainPage_79092a156bed07fd24ba9e19c71a1e65_XamlApply((MainPage_79092a156bed07fd24ba9e19c71a1e65XamlApplyExtensions.XamlApplyHandler0)(c0 => 
    			{
    				global::Uno.UI.FrameworkElementHelper.SetBaseUri(c0, "file:///C:/Users/PC/source/repos/App46/App46/App46.Shared/MainPage.xaml");
    				c0.CreationComplete();
    			}
    			))
    			;
    			
    			this
    			.Apply((c1 => 
    			{
    				// Source C:\Users\PC\source\repos\App46\App46\App46.Shared\MainPage.xaml (Line 1:2)
    				
    				// WARNING Property c1.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}Page, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator
    			}
    			))
    			.Apply((c2 => 
    			{
    				// Class App46.MainPage
    				global::Uno.UI.FrameworkElementHelper.SetBaseUri(c2, "file:///C:/Users/PC/source/repos/App46/App46/App46.Shared/MainPage.xaml");
    				c2.CreationComplete();
    			}
    			))
    			;
    			OnInitializeCompleted();
    
    			// Force materialization of x:Name resources, which will assign them to named property field.
    			object _ = null;
    			// Source ..\..\..\..\App46.Shared\MainPage.xaml (Line 11:10)
    			Resources.TryGetValue("MyDataTemplate", out _);
    			Loading += (s, e) =>
    			{
    				MyDataTemplate.UpdateResourceBindings();
    			}
    			;
    		}
    		partial void OnInitializeCompleted();
    		private class _MainPage_79092a156bed07fd24ba9e19c71a1e65_App46MainPageSC0
    		{
    			public _View Build(object __ResourceOwner_4)
    			{
    				var nameScope = new global::Windows.UI.Xaml.NameScope();
    				_View __rootInstance = null;
    				__rootInstance = 
    				new global::Windows.UI.Xaml.Controls.Grid
    				{
    					IsParsing = true,
    					// Source ..\..\..\..\App46.Shared\MainPage.xaml (Line 12:14)
    				}
    				.MainPage_79092a156bed07fd24ba9e19c71a1e65_XamlApply((MainPage_79092a156bed07fd24ba9e19c71a1e65XamlApplyExtensions.XamlApplyHandler0)(c3 => 
    				{
    					global::Uno.UI.FrameworkElementHelper.SetBaseUri(c3, "file:///C:/Users/PC/source/repos/App46/App46/App46.Shared/MainPage.xaml");
    					c3.CreationComplete();
    				}
    				))
    				;
    				if (__rootInstance is DependencyObject d)
    				{
    					global::Windows.UI.Xaml.NameScope.SetNameScope(d, nameScope);
    					nameScope.Owner = d;
    					global::Uno.UI.FrameworkElementHelper.AddObjectReference(d, this);
    				}
    				return __rootInstance;
    			}
    		}
    	}
    }
    namespace App46.Skia.Gtk
    {
    	static class MainPage_79092a156bed07fd24ba9e19c71a1e65XamlApplyExtensions
    	{
    		public delegate void XamlApplyHandler0(global::Windows.UI.Xaml.Controls.Grid instance);
    		[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    		public static global::Windows.UI.Xaml.Controls.Grid MainPage_79092a156bed07fd24ba9e19c71a1e65_XamlApply(this global::Windows.UI.Xaml.Controls.Grid instance, XamlApplyHandler0 handler)
    		{
    			handler(instance);
    			return instance;
    		}
    	}
    }

    The actual bug here is that we don't generate a backing field for MyDataTemplate. This may get fixed with #7108, but can't say for sure without testing.

  3. added
    area/xBind 🪢
    and removed
    triage/untriaged
    on Oct 6, 2021
  4. jeromelaban commented on Oct 6, 2021

    @jeromelaban
    Member

    Thanks @Youssef1313 for the validation. @dojo90 you may work around the issue by using x:Key instead of x:Name (unless you actually need to use the x:Name from the code behind).

  5. changed the title [-]error CS0117: "NavigationViewItem" does not contain a definition for "UpdateResourceBindings".[/-] [+]error CS0117: `NavigationViewItem` does not contain a definition for `UpdateResourceBindings`[/+] on Jul 19, 2023
  6. added
    difficulty/medium 🤔
    area/code-generation
    and removed
    difficulty/tbd
    on Jul 19, 2023
  7. github-actions commented on Aug 1, 2025

    @github-actions
    Contributor

    Hey there — just a heads-up that this issue has been quiet for over a year. If there’s no update or comment in the next 10 days, it’ll be closed automatically. Feel free to remove the stale label or drop a note to keep it open.

  8. added
    stale
    on Aug 1, 2025
  9. MartinZikmund commented on Aug 1, 2025

    @MartinZikmund
    Member

    Still relevant

  10. removed
    stale
    on Aug 1, 2025
  11. MartinZikmund commented on Apr 8, 2026

    @MartinZikmund
    Member

    Repro generator

    This issue was classified as not reproducible with a code sample or test.

    Reason: Code generation bug — NavigationViewItem missing UpdateResourceBindings definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationarea/xBind 🪢difficulty/medium 🤔kind/bugno-repro

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions