Problem rebinding viewmodel to usercontrol
See original GitHub issueHi I have problem in conductor page, I thing it may be a bug.
I have Conductor<IScreen>
that is holding one and only active viewModel (DashboardViewModel or LoginViewModel)
In xaml I have:
<!-- it is visible only when Login is not null ->
<con:myControl1 cal:Bind.Model="{Binding LoginViewModel}" />
<!-- it is visible only when Dashboard is not null ->
<con:myControl2 cal:Bind.Model="{Binding DashboardViewModel}" />
in myControl1 I have another control in myControl1 with binding text and events to action
<TextBox x:name="SomeText" />
<con:PinKeyboard
x:Name="keyboard"
cal:Message.Attach="[Event CharAdded] = [Action CharAdded($eventArgs)]; [Event CharRemoved] = [Action CharRemoved]" />
In conductor I switch betwean DashboardViewModel and LoginViewModel. (Only one is active) and at activation time it is created new one:
if (logout) {
LoginViewModel = new LoginViewModel(); // It is notif. property.
ActivateItem(LoginViewModel);
}
At first start everything is fine. CharAdded is calling. But if I recreate LoginViewModel after user logout, it is not rebinding to user control.
I try:
<con:myControl1 cal:Bind.ModelWithoutContext="{Binding LoginViewModel}" />
It is not working also, and “SomeText” isn’t filled at all.
I try also:
<myControl1 DataContext="{Binding LoginViewModel}" cal:Bind.ModelWithoutContext="{Binding}" />
It works only first time, second time, SomeText is binding to new value but, attatchet actions (e.g CharAdded ) are executed on old ViewModel.
How I can switching betwean viewModels with binding and actions?
Thank for answer (and sorry for bad english 😃)
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@matopeto What you are looking for is described in in http://caliburnmicro.com/documentation/composition#multiple-views-over-the-same-viewmodel. Please use StackOverflow for questions and not the issue tracker.
Ok, this requirement seems different from your first post and I’m a bit confused.
For the first post about essentially having two separate states for your view model (using a conductor). One way to achieve this is make use of the Conductor’s
ActiveItem
property that will get changed depending on whether you active LoginViewModel or DashboardViewModel.Your view would contain something like:
This would mean for instance when you logout and activate LogOutViewModel the view changes to the correct view and binds correctly.
You’re right this is using the 1:1 relationship. If you’re looking to break the panorama items up into separate views / view models then your PanoramaViewModel could inherit from
Conductor<IScreen>.Collection.OneActive
where you create a collection of view models, each corresponding to a separate view for each of the panorama items.