Cannot refresh datacontext

Sep 14, 2011 at 8:04 AM

I have a usercontrol and  its corresponding viewmodel. The usercontrol contains the fabtab control. The viewmodel contains an observable collection of views which serves as the itemsource for the fabtab control.

Now somewhere along the logic of the application I create a new object of the viewmodel and set it as the datacontext of the usercontrol. The fabtab control still continues to show the old set of tabs. Why?

Sep 14, 2011 at 10:31 AM

I would like to add that this behavior is new, it used to work fine a few days back.
Solving this issue is very urgent for me right now. I would appreciate a little help or direction.

 

- Futurix

Coordinator
Sep 14, 2011 at 12:12 PM

So, I think what you are saying is that you've got your UserControl (including the FabTab control) successfully data bound to some instance of your ViewModel which exposes an ObservableCollection.  At some point you create a new instance of the ViewModel and now you set this new instance to the data context of your user control.  That's my understanding of your problem.

In the past when dealing with changing DataContext, I've seen that it helps to set it to null before actually setting it to the new value you want it to be.  You might also try raising INotifyPropertyChanged on your collection property after datacontext has been set.

As an aside, are you seeing all of the other stuff on your screen changing as expected, just not the FabTab?  Another thing to try would be temporarily comment out your FabTab control and replace it with the standard WPF Tab control and see if it behaves any differently.

Sep 14, 2011 at 12:34 PM

Hey Josh

Your understanding of my problem is perfect.

All other stuff in the usercontrol except the FabTab change to reflect the new datacontext. Even tried setting the datacontext to null, in which case all other stuff show blanks but FabTab continues to show the old set of tabs. Tried raising INotifyPropertyChanged too, still no dice. Moreover the WPF Tab Control works properly and changes to reflect the change in datacontext.

- Futurix

 

Coordinator
Sep 14, 2011 at 12:47 PM

If you zip up your project and send it to me, or zip up a sample project that mimics what you are seeing I will have a look at it.  Send it to adajos@hotmail.com

Josh

Sep 14, 2011 at 1:03 PM

Ok will do that.

On a second note is there any method in FabtabControl which is responsible for refreshing the contents which if commented would be causing this?

I have edited quite some stuff, the way it gets thumbnails, previews in content tab, functionality to keep link to closed tabs in contents tab, always visible contents tab.

All of this was working fine 2 days back. Formatted the code, cleaned indentation etc and now this issue occurs.

 

- Futurix

Sep 15, 2011 at 6:39 AM

Hi

I have pin-pointed the problem after a long session of debugging. Found that the problem is not due to my modifications to FabTab, but is intrinsic in the latest changeset of FabTab.

It turns out that, once the contentstab is added to an instance of FabTab which is linked to some itemsSource, then this instance of fabtab gets fixated on the loaded itemsSource and will not change to reflect a new itemsSource. The problem persists even if we remove the contentstab by closing all but one tab in the loaded itemsSource. The initial loading of the contentsTab somehow breaks the binding with the itemsSource.

I have made some changes in the Fabtab Sample application to showcase the bug. Sending a zipped copy of the same to your email address ( adajos@hotmail.com ). Check my comment in the loadDummyData() of window1.xaml.cs

- Futurix 

Sep 15, 2011 at 8:39 AM

Ok Just realized. Its not just the addition of contentstab that breaks the binding. Any modification to the originally loaded itemsSource ( re-ordering of tabs , closing of tabs, adding contentstab) breaks it.

- Futurix

Coordinator
Sep 15, 2011 at 2:38 PM

Futurix,

Check your email.  Hope that helps, bottom line is that a workaround is the best I can come up with quickly.

You can modify an existing ItemsSource just fine--adding/removing tabs, etc but when you change the ItemsSource alltogether or change the DataContext that is when things get weird.

Let me know if that helps.

Josh

Coordinator
Sep 15, 2011 at 2:41 PM

Hmmm....Futurix, I see that the email I sent to you at your gmail account just bounced.  Do you have a different address I can send some code to?

Sep 15, 2011 at 2:48 PM

Hey Josh

Thanks a lot. I've just dropped you another mail from my alternative email address. But that too is on gmail. Hope it works.

- Futurix

Sep 15, 2011 at 3:51 PM

Josh,

Got your mail with the comments and code attached. Gmail doesn't allow the users to send or receive attachments with executables or archives containing executables. The rename trick worked just fine. For the same reason, earlier today, I had to use a filesharing service to send you the sample code .

Anyways so coming back to the issue at hand, I ended up tackling the problem by removing FabTab and placing a contentPresenter instead in my usercontrol. Placed the FabTab in a separate new usercontrol, which contains only FabTab. Now whenever I need to change the ItemsSource I create a fresh instance of the new usercontrol (which contains new instance of FabTab binded to new itemsSource) and plug it in as the content of the contentPresenter in my original usercontrol. I hope that made sense. 

I went through your solution. Looks like there is quite a bit of hacking involved.

Thanks a bunch for your replies.

- Futurix

Coordinator
Sep 15, 2011 at 3:55 PM
Your solution seems like a better workaround to me. Also nice in that it doesn't required exposing a bunch of private stuff from FabTab.

Good work, hope it works out for you.


From: [email removed]
To: [email removed]
Date: Thu, 15 Sep 2011 08:51:36 -0700
Subject: Re: Cannot refresh datacontext [fabtab:272527]

From: Futurix
Josh,
Got your mail with the comments and code attached. Gmail doesn't allow the users to send or receive attachments with executables or archives containing executables. The rename trick worked just fine. For the same reason, earlier today, I had to use a filesharing service to send you the sample code .
Anyways so coming back to the issue at hand, I ended up tackling the problem by removing FabTab and placing a contentPresenter instead in my usercontrol. Placed the FabTab in a separate new usercontrol, which contains only FabTab. Now whenever I need to change the ItemsSource I create a fresh instance of the new usercontrol (which contains new instance of FabTab binded to new itemsSource) and plug it in as the content of the contentPresenter in my original usercontrol. I hope that made sense.
I went through your solution. Looks like there is quite a bit of hacking involved.
Thanks a bunch for your replies.
- Futurix
Read the full discussion online.
To add a post to this discussion, reply to this email (fabtab@discussions.codeplex.com)
To start a new discussion for this project, email fabtab@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com