Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wieslawsoltes opened this issue Apr 12, 2019 · 5 comments
Closed

Comments

@wieslawsoltes
Copy link
Collaborator

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">
@worldbeater
Copy link
Contributor

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.

@patrickklaeren
Copy link

Docs have moved to https://docs.avaloniaui.net/docs/getting-started/ide-support#design-time-properties FYI

@EricEzaM
Copy link
Contributor

EricEzaM commented Jun 10, 2022

Somewhat related: Whenever I use d:DataContext or Design.DataContext, the Rider previewer stops updating. If I have the design datacontext set and then changing a margin, for example, the preview will not update. As soon as I remove the design datacontext line, the preview updates.

ForNeVeR/AvaloniaRider#209

@maxkatz6
Copy link
Member

@EricEzaM your app most likely has some errors that break the previewer. Check rider logs in Avalonia Designer tab, also see similar issue #8295

@EricEzaM
Copy link
Contributor

EricEzaM commented Jun 10, 2022

Yes thank you, that issue is exactly what I am having. This is just the issue that showed up when I googled the problem :P I have commented and will continue discussion there.

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

No branches or pull requests

6 participants