question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem rebinding viewmodel to usercontrol

See original GitHub issue

Hi 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:closed
  • Created 9 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tibelcommented, Jun 27, 2014

@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.

0reactions
nigel-sampsoncommented, Jun 26, 2014

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:

<ContentControl x:Name="ActiveItem" />

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set DataBinding for UserControl with ViewModel
1 Answer. A UserControl that is supposed to operate on a particular view model class - or more precisely on a class with...
Read more >
How to bind from ViewModel to controls in usercontrol
Hi; I'm using wpf here mvvm. I have some questions. Right now I'm binding from CategoryViewModel to an ListView - this works perfect....
Read more >
Binding to a UserControl that has its own ViewModel (MVVM)
My problem is that the binding on the dependency property only works when the UserControl doesn't have a ViewModel as the DataContext, ...
Read more >
Propagate bindings on ViewModel of UserControl #2596
I have a UserControl that uses a ViewModel. I want to be able to set a property on the ViewModel of the control...
Read more >
WPF UserControl Reuse With MVVM
You have a UserControl with DependencyProperty -ies named ... Binding, in WPF, does not care about class types, only about property names.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found