Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What I want to make a character status popup? #70

Unanswered
locus84 asked this question in Q&A
Discussion options

I want to set initial parameter for the viewmodel that is made for a character status.
but it looks like I can't feed my own viewmodel to a CanvasView as it requests the viewmodel when awake.
I'm new to mvvm so teach me how to. thank you in advance.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

You can override the base viewmodel instance creation. Docs.

public class CounterView : CanvasView<CounterViewModel>
{
 // Override the base viewmodel instance creation.
 // Required in case the viewmodel doesn't have a parameterless constructor.
 protected override CounterViewModel GetBindingContext()
 {
 return new CounterViewModel(69);
 }
}
You must be logged in to vote
1 reply
Comment options

Thanks! I saw docs and also checked source code.
I initially thought I can pass some parameters using ctor of CounterViewModel itself as you suggested.
But after digging up VContainer and the MvvmToolkit sample, it looks like I need some kind of Broker or through DI container.

public class CounterView : CanvasView<CounterViewModel>
{
 // Override the base viewmodel instance creation.
 // Required in case the viewmodel doesn't have a parameterless constructor.
 protected override CounterViewModel GetBindingContext()
 {
 return _scopedContext.Resolve<CounterViewModel>();
 //or
 return new CounterViewModel(_scopedContext.Resolve<ICounterBroker>().value);
 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /