Unable to use Previewer with Dependency Injection #13743
-
Describe the bugCurrently, AvaloniaUI's previewer can not work well when I use To Reproduce
Expected behaviorThe preview window should have the rendered controls instead of errors Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 30 replies
-
|
Try if(Design.IsDesignTime) |
Beta Was this translation helpful? Give feedback.
-
Is there a way to detect the previewer using the compile symbol? I don't want those codes to be present in the production publish. |
Beta Was this translation helpful? Give feedback.
-
|
It doesn't look like an issue. The error message is pretty descriptive and specific. |
Beta Was this translation helpful? Give feedback.
-
|
Can someone please share a complete implementation about this, I'm not able to get it working, I have the @thevortexcloud implementation and Added the cc @jp2masa Now I'm getting the same error as @leowest77 LastUpdate: It's wokring now, I had to add constructor with the Type field, and add the markup namespace to the view |
Beta Was this translation helpful? Give feedback.
In my projects I usually create a dummy DI container and then do something like
Design.DataContext={markup:DesignResolve {x:Type vm:MainViewModel}}, with a custom markup extension that resolves view models from the dummy container.I believe it could be simpler, for example by creating a base class for views or overriding the default value for
Design.DataContextProperty.Additionally, if you want to use DI with views as well, I think overriding the default value for
Design.PreviewWithPropertywould work.