question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

x:DataType doesn't work with nested types from other assemblies

See original GitHub issue

Describe the bug

Using x:DataType doesn’t work with nested types from other assemblies.

Consider the following viewmodel code:

public class RootViewModel
{
    public IEnumerable<object> Sections { get; } = new[] { new NestedViewModel() }; 

    public class NestedViewModel
    {
        public string SampleText => "Hello world";
    }
}

NOTE: this code must be placed in a separate project (eg. a .NET Standard 2.0 lib) to repro the issue. It works fine if the classes are right in the UWP app project.

And the following XAML code:

<Page
    x:Class="BindToNestedTypeRepro.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:libs="using:BindToNestedTypeReproLibs">
    <Page.DataContext>
        <libs:RootViewModel x:Name="ViewModel"/>
    </Page.DataContext>

    <Grid>
        <ListView ItemsSource="{x:Bind ViewModel.Sections}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="local:RootViewModel+NestedViewModel">
                    <TextBlock Text="{x:Bind SampleText}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Page>

The app will fail to build and that data type for the template will not be recognized.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create a .NET Standard 2.0 project and add the viewmodel code
  2. Create a new blank UWP app and reference the other project
  3. Paste that XAML code above in MainPage
  4. Try to build and run

Expected behavior The app should run normally and XAML should recognize the data type and see the properties in the model.

Screenshots

image

Version Info

NuGet package version: n/a

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
baskrencommented, Nov 5, 2021

Thanks Sergio for being a good sport. Sorry … I guess I just needed to vent a bit.

2reactions
Sergio0694commented, Nov 5, 2021

Yes, using XAML is clearly a terrible idea because of this one bug. For the same reason, using C# is also a terrible idea because one time I found a bug in the C# compiler.

This is not the right place to have this conversation, and that comment is completely off topic. There is a separate proposal to create data templates in C#, I’d recommend subscribing there if you’re interested 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference nested enum type from XAML
It looks like this is just a bug with the VS 2010 designer. The designer complains that Type MyNamespace:MyClass+MyEnum was not found ....
Read more >
Untitled
Wpf xaml nested types are not supported WebJul 16, 2020 · In my XAML, ... WebSep 3, 2020 · x:DataType doesn't work with...
Read more >
Type.IsNestedAssembly Property (System)
Gets a value indicating whether the Type is nested and visible only within its own assembly.
Read more >
Proposal: Importing STEP assemblies as nested layers, not ...
A solution that we've been working toward in that thread for bringing in nested assemblies from STEP files, and representing them in Rhino ......
Read more >
Unity nested namespace. fbs"; This makes it easier to refer
Question The type or namespace name 'ImageEffects' does not exist in the namespace. The Adjust Namespaces dialog will open. Scenegraph and the other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found