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.

Add support for d:DesignInstance when using d:DataContext in designer

See original GitHub issue

Error:

Cannot create unknown type '{http://schemas.microsoft.com/expression/blend/2008}DesignInstance'.

Repro:

<UserControl x:Class="Draw2D.Views.MainView"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:editor="clr-namespace:Draw2D.Editor"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance Type=editor:CanvasEditor, IsDesignTimeCreatable=True}"
             d:DesignWidth="800" d:DesignHeight="600">

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
worldbeatercommented, Nov 1, 2020

For those who came across this issue while looking for a way to set a design-time DataContext. In Avalonia, this works as easy as:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="clr-namespace:AssemblyName.DesignTime;assembly=AssemblyName"
             x:Class="AssemblyName.Views.LoginView">
    <Design.DataContext>
        <d:DesignTimeLoginViewModel />
    </Design.DataContext>
</UserControl>

See also: https://avaloniaui.net/docs/quickstart/vs-designer#design-time-properties

Should be quite easy to add support for d:DesignInstance, we just need to write a custom IXamlAstTransformer I guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binding data context to view using DesignInstance
Binding data context to view using DesignInstance · 1. Try to use d:DataContext="{d:DesignInstance ViewModels:VM1}". – Pavel Anikhouski. Feb 10, ...
Read more >
Sample data on the design surface, and for prototyping
In the Properties window, find the DataContext property (inside the Common category), and modify it. Select your view model type from the Select ......
Read more >
XAML Intellisense fails to populate with values from a ...
XAML Intellisense fails to populate with values from a DataContext declared using d:DesignInstance after a project is built/run.
Read more >
How to use d:DataContext and dxmvvm:ViewModelSource
In the designer, this displays the warning "Cannot resolve property 'ToolTip' in data context of type 'object'. So I define d:DataContext: C#. < ......
Read more >
Usable WPF Design-Time Data for .NET 5.0 (and 6.0)
I find design-time support essential for successful WPF view design, ... I could see us making using of d:DesignInstance is either by adding...
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