Pivot control - win rt

Nov 5, 2013 at 10:34 AM
For some reason when I use the Pivot control from the MyToolkit, I'm no longer able to directly access the controls inside it in my code behind of the xaml page.

Example: mainpage.xaml has textbox Username, in code behind I do this.Username.Text = "blabla" this works on a normal page.

When the Textbox get's wrapped inside a PivotItem of the Pivot control this.Username is NULL in code behind.

Any suggestions?
Nov 5, 2013 at 11:23 AM
This problem was always there... until now i couldn't find a solution for it. I think its because the way the items are instantiated - they are dependency properties of FrameworkElements. I don't know a way to avoid this problem... Maybe there is some XAML specialist which can fix this?
Nov 5, 2013 at 11:25 AM
Ok thanks for the answer... let's hope someone has an idea to circumvent this.
Nov 5, 2013 at 11:26 AM
I'll try to create a simple control with the same problem and ask a question on StackOverflow...
Nov 5, 2013 at 2:53 PM

The Pivot sets its content in its code behind, so your Username control disappears from the visual tree at runtime. You have to call this.FindName("Username") to find the control. It will only be found when the PivotItem on which it sits, is selected (otherwise FindName will return a null).

Hope this helps,
Nov 5, 2013 at 2:57 PM
Ok, currently only the current visible pivot is set into the ContentPresenter control. What if all pivot FrameworkElements are placed in a Grid and only the visible one is set to Visibility=Visible. This should work... Also all pivots are loaded - which may be good or bad... What do you think?
Nov 5, 2013 at 6:15 PM
Well what does the win phone version do? I would suggest it loads all controls, no?
Never really looked at the control loading that way... only did some data loading tricks on pivot change in win phone to not fill up memory at the beginning.

But now I'm dealing with an input page with a lot of controls, I would like to seperate. So if they all get loaded, I wouldn't mind.
Nov 5, 2013 at 6:26 PM
I think on wp they are not preloaded...

For now, why not create a control for each pivot to separate them? This way you can also give the elements a name?

I'm trying to improve the control, but I'm not sure if it works without performance impacts...
Nov 5, 2013 at 6:28 PM
With the current version and Diederik his little help, all is working ok, so no worries about updating the control. It's not that needed anymore!
Thanks for the toolkit by the way! :)
Nov 5, 2013 at 6:29 PM
So you are now using .FindName(...) on runtime and this works? But variables are not set this way, or are they?
Nov 5, 2013 at 6:31 PM
Indeed using the FindName method.
Not sure what you mean by the variables?
Nov 5, 2013 at 6:33 PM
If you have a x:Name="test" in the xaml, you can access the control in the view's code-behind using the variable test: this.test... but if x:name is on an element inside pivot it is null (not loaded).
Nov 5, 2013 at 6:35 PM
yes indeed!
That is the case now... but like I said it's not that big of a deal now... because the actual data is mvvm databound.
Only for a filepicker I need to access the textbox once..
Nov 6, 2013 at 6:38 AM
I've updated the control, so that the pivots are preloaded but this still does not solve your problem (but FindName should work). If you have the time, check out the code from SVN and try the newest version (no NuGetPackage available yet).

Also updated the documentation: https://mytoolkit.codeplex.com/wikipage?title=Pivot
Nov 6, 2013 at 7:31 PM
Now available as nuget update
Nov 6, 2013 at 7:35 PM
Ha cool, thx!! Will update the package