Setting the design time datacontext making the designer stop responding
See original GitHub issueI followed the Avalonia docs to set the datacontext but whenever I set it the designer suddenly stops responding to changes and hangs up until I remove the datacontext:
I tried setting it using: d:DataContext="{x:Static dd:McalUiViewModelDesignData.ViewModel}" and
<Design.DataContext> <viewModels:ViewModel /> </Design.DataContext>
and both doesn’t work
NOTES: I am using jetbrains rider IDE version “2022.1.1” and avaloniaRider version “1.0.0.2140933515”
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Setting design time DataContext on a Window is giving a ...
Essentially I learned something new. The d: namespace prefix that Expression Blend/Visual Studio designer acknowledges is actually ignored/" ...
Read more >WPF Design time binding not working
1.1 to 16.1.3 the WPF design time data isn't working. I get the name of Property I am binding to but not the...
Read more >Use Design Time Data with the XAML Designer in Visual ...
The XAML Designer stopped working Try closing and reopening the XAML file, and cleaning and rebuilding your project.
Read more >Using Design-time Databinding While Developing a WPF ...
A trick that allows populating a user control with sample data while you are designing it in the Visual Studio designer.
Read more >Usable WPF Design-Time Data for .NET 5.0 (and 6.0)
Shows design-time data consisting of values that are not what I specified in the Each WholeStatisticView instance in the designer is using the ......
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 Free
Top 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

I just had a bug like this where my data context constructor was running into an exception. This unhandled exception doesn’t seem to be logged anywhere. After a lot of looking I realized what the problem was for me (I specifically removed the initialization of a component that is actually needed in design mode). I’m not 100% sure it was an exception, only just pretty sure based on the fact I was using a
IServiceProviderthat had a missing service and the preview started working once I added the service I realized was missing.So it would be very nice if the rider avalonia output would show something more than:
when there are problems like this.
Just leaving this here in case someone else stumbles into this problem. I encountered the same issue as described by @hhyyrylainen where the logfile of the designer showed the following:
In my case, I’m using the MVVM toolkit and inject the viewmodel into the view using the following
Then I added a design time reference to the view to preview my data:
Turns out that I forgot to register the viewmodel for usage with dependency injection. After registering it, the preview started working.
And I agree that the previewer should preferably give more helpful error message on what is actually happening 😃