You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: How about a feature that creates a ViewModel parallel to your actual ViewModel which you can use with the d:DataContext attribute?
A common annoyance I encounter is bringing in example data to view in the XAML designer. The way I currently do it is creating 3 files:
The actual ViewModel class
An interface defining everything that View and ViewModel interact over
A DesignTimeViewModel class that implements said interface and delivers example data
I then bind the DesignTimeViewModel to the window/user control/whatever in the XAML file using d:DataContext="{d:DesignInstance myNamespace:MyDesignTimeViewModel, IsDesignTimeCreatable=True}".
So my ViewModel might have a public int CurrentViews { get; set; } and the DesignTimeViewModel might have a public int CurrentViews { get => 130; set => throw new NotImplementedException(); }. As you can imagine, this is quite tedious to work with, so my idea would be to use specific attributes and source generators to automatically create those DesignTimeViewModels.
This is a rough idea at an early stage, so I'd love to hear some feedback. Do you think the Toolkit would benefit from this or should I rather go ahead and create my own project? Should it be implemented in a way that those attributes can be used alongside existing [ObservableProperty] generators or would that cause trouble? Any pitfalls you foresee? What datasources to use? I mean, generating a random number between X and Y is easy, but pulling a random name from a list requires said list in the first place.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone!
tl;dr: How about a feature that creates a ViewModel parallel to your actual ViewModel which you can use with the
d:DataContext
attribute?A common annoyance I encounter is bringing in example data to view in the XAML designer. The way I currently do it is creating 3 files:
I then bind the DesignTimeViewModel to the window/user control/whatever in the XAML file using
d:DataContext="{d:DesignInstance myNamespace:MyDesignTimeViewModel, IsDesignTimeCreatable=True}"
.So my ViewModel might have a
public int CurrentViews { get; set; }
and the DesignTimeViewModel might have apublic int CurrentViews { get => 130; set => throw new NotImplementedException(); }
. As you can imagine, this is quite tedious to work with, so my idea would be to use specific attributes and source generators to automatically create those DesignTimeViewModels.For example:
should create
This is a rough idea at an early stage, so I'd love to hear some feedback. Do you think the Toolkit would benefit from this or should I rather go ahead and create my own project? Should it be implemented in a way that those attributes can be used alongside existing
[ObservableProperty]
generators or would that cause trouble? Any pitfalls you foresee? What datasources to use? I mean, generating a random number between X and Y is easy, but pulling a random name from a list requires said list in the first place.Thanks for your thoughts and insights,
Tommycore
Beta Was this translation helpful? Give feedback.
All reactions