x:DataType doesn't work with nested types from other assemblies
See original GitHub issueDescribe 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:
- Create a .NET Standard 2.0 project and add the viewmodel code
- Create a new blank UWP app and reference the other project
- Paste that XAML code above in
MainPage
- 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
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:
- Created 3 years ago
- Reactions:3
- Comments:9 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks Sergio for being a good sport. Sorry … I guess I just needed to vent a bit.
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 🙂