I am trying to dynamically fill a second panorama page based on what item was selected from the home application screen.
On the application's first start screen there is a listbox if items each with text. If a user taps on an item with text "foobar" a template page should load and the title of the template page should be set to "foobar" and this second panorama page should know that it's data should be related to "foobar".
Is there anyway to do this?
I currently have my MainPage navigate to a new page (DynamicPage.xaml). This navigation is triggered when a ListBox_SelectionChanged event occurs. I have the title text of the DynampicPage.xaml Binding to a TitleText variable that is located in MainPage.xaml.cs. However, when I do this the title of DynamicPage.xaml is ever only set to my initialization value for the titleText variable even though I am updating this variable right before I navigate to the page.
If anyone can provide some help I would be very grateful as I am just a beginner on the WP7 platform. Thanks!
The Binding you're using for the title is only going to update if the TitleText property is a dependency property or if your MainPage is implementing the INotifyPropertyChanged interface so your class can notify the UI when one of its properties changed.
http://windowsphonegeek.com/articles/All-about-Dependency-Properties-in-Silverlight-for-WP7
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.95).aspx
But I think this is not the best way for you to achieve this. For now a much better way is to store your data somewhere in a static class, in the main page's constructor load these data into the listbox, and when the user selected an item, navigate the user to the second page like this:
NavigationService.Navigate(new Uri("/DynamicPage.xaml?Item=" + selectedItem.Id, UriKind.Relative));
When you navigate like this a new instance of DynamicPage is created, and in the OnNavigatedTo method you can access the navigation parameters and populate your page with the selected data. For example:
<controls:Panorama x:Name="MyPanorama" Title="TitleHere">...</controls:Panorama>
Item selectedItem = StaticData.GetItem(NavigationContext.QueryString["Item"]);
MyPanorama.Title = selectedItem.Name.ToUpper();
Description.Text = selectedItem.Description;
This way you can use secondary tiles and toast notifications to directly point to a specific content in your application.
If you're getting to understand the navigation you should definitely use the pattern called Model-View-ViewModel which is about to solve these problems mostly with bindings, but trust me, probably this is the easier way for now.
Related
I need an idea, please. I have a Details form which shows the fields of a model (about 10 fields in all). There are three modes in which I could show this view - in mode "Edit", in mode "New" (which, of course, is like an edit but without values), and in mode "View" (no changes allowed, just labels).
I could of course create three Details pages, one for each mode, and call them selectively, but I would like to have just one and pass the "DocumentMode" parameter to it. That View should bind to that mode and selectively show/hide controls, probably like "DocumentMode = VIEW => Show labels" or "DocumentMode = EDIT => Show Entry or Editor, show DatePicker, TimePicker, etc".
My question is this: How do I show/hide these groups of controls depending on the DocumentMode parameter ? Which would be the best way to do this ? I could probably bind the "IsVisible" property to my documentMode parameter, but I think that is a really ugly solution (and I assume that regardless of whether the controls are used or not in a specific mode, they will all be loaded anyway).
Thank you.
Alex
I think you can use a Listview or Collectionview to represent your data because you mentioned that you have 10 fields.
In addition, you said you need a "new" button, so you can set it at the top of the app as a button, when you click the button then you jump to another page which is blank and you can add the data.
This must refer to the shell you may need to set a navigation.
Then the "view" and the "edit" you can use the property SelectionChanged to control the item, I mean when you click the item in collectionview, the SelectionChanged method can be triggered and turn to another page which can show the detail about the item you clicked. In the page you can view and edit the data.
Here are some articles you might be able to use: Listview, Collectionview, Shell
If you have more information to add, please kindly share with me.
In KendoUI, how do I select a treeview element if it does not have an ID? Like by the style class or something.
I am writing an MVVM application and there are 2 tabs in a kendo tab strip with each containing a treeview. On selecting one tab, I want it's checkboxes to be updated based on what checkboxes were checked in the other tab and then I want to also call updateIndeterminate() on the treeview it contains within it.
Now, since I am using MVVM, I don't want to access the treeview by it's id. All I can find online on searching is $("#treeView") and in the Telerik forums, the example to call updateIndeterminate() is also this -
var treeview = $("#treeview").data("kendoTreeView");
treeview.updateIndeterminate();
Am I missing something here? I wonder why it's so hard to find.
I suppose the reason why it's hard to find is that it goes against the idea of declarative initialization and the separation of view and model. Your code is not supposed to interact with the widget itself. Instead, all your logic should be wired up in your view model which is bound to the UI.
You can certainly find it without an id, e.g. with something like this:
var treeView = $("ul[data-role=treeview]").first().getKendoTreeView();
or by using the .k-treeview class, but I wouldn't recommend it. If you really need to access it in code, you should give it an id.
All, I am new to Windows 7 Phone. My situation is that I have a main page which contains a ScrollViewer which in turn houses a StackPanel. I want to populate this StackPanel with multiple sub-StackPanels (at runtime) which are to hold an Image Thumb nail a hyperlink and some basic information about the image.
This is all good when I do this from the main page, but I want to know how to update this control (which is on the main page), but from any page other than the main page. I would like to know what is considered best practice for updating a page's control (like that outlined above) from another page.
Obviously there are a number of ways to pass data between pages
PhoneApplicationService.Current.State["yourparam"] = param
NavigationService.Navigate(new Uri("/view/Page.xaml", UriKind.Relative));
then in other page simply
var k = PhoneApplicationService.Current.State["yourparam"];
and many others. But what is best practice for updating a generic control from a different page?
Note: There are many question about data access and passing between pages.
Passing data from page to page
How to pass the image value in one xaml page to another xaml page in windows phone 7?
Passing image from one page to another windows phone 7
and more. This is not what I am asking.
If I understand your question correctly, you are trying to update a control which is on for example MainPage.xaml from another page for example Page2.xaml.
As far as I know there is no way to reach a pages controls from another page, and that seems unnecessary for the cases that I can think of.
The method used to achieve what you are trying is usually done by triggering an action (like the press of a button ) and passing a parameter to the page you are trying to update the control. And on that page's onnavigatedto event (or viewmodel constructor if you are using the MVVM pattern), update your control based on the passed parameter.
If your update is based on data then the best practice is to bind an observable collection or an object that extends the INotifyPropertyChanged (basically any object that can signal that one of their property changed to the ui) and change the data based on the parameter that is passed.
If these two pages somehow are visible at the same time and there is no navigation needed between them( like a popup or sliding menu kind of ui) then you can make the page that you are showing in the popup a usercontrol, and reach to the parent's controls by this.Parent.
I can be more helpful if you give more specifics about your app's flow.
The MVVM pattern would be a good way to go. Saying MVVM is too complicated for small teams isn't exactly accurate - the purpose of MVVM is to decouple Silverlight or WPF code. Using the codebehind of a Silverlight page to directly access data creates coupling in your code and accrues technical debt. Whether you're one developer or 100, if your UI is coupled with your data classes, if you have to change your data classes, you will have to make changes to every UI element that uses those classes. This takes longer and makes your application more difficult to change.
MVVM makes it so your UI (the View) doesn't know anything about the data (your Model). The ViewModel is the code in between that the UI can bind to, and which manages events in the UI that need to be persisted to the Model, and also changes in the Model that need to be represented in the View. For this reason, it handles events, and that's what it sounds like you need in your code - an event that can exist off of the codebehind, that can update the Views bound to it when the data changes. If you have two pages, then an event on one of the pages will be sent to the ViewModel, which will make a change to the Model (data) if necessary, and pass it back to the ViewModel. The ViewModel would then update any of the UI elements (Views) bound to that piece of data.
There's a REALLY good demonstration of how to implement the MVVM design pattern here
. The guy goes through and takes a typical WPF application (just like Silverlight), where the UI codebehind implements event handlers that directly access data, and refactors it using the MVVM pattern.
I'm starting writing my little app at WP7. I consider one thing. There is event "AtStart"? I want to use Textbox to display actual data with some text and I thought that event "atstart/atLaunch" will be perfect for it.
Thanks
There is no "AtStart" event - there is an Application.Launching event which is fired when your application starts up. There is also an OnNavigatedTo virtual method you can override on a page level which is invoked when a page is first navigated to. It sounds like OnNavigatedTo might be what you are looking for. At this point you can change the Text property of a TextBlock (which is identified by an x:Name) which is present in your page XAML file.
I am currently working on a project which requires multiple views of the same viewmodel. Let me describe this way:
ViewModel: CustomerDetailsViewModel.cs (inherited from Screen class)
View: CustomerDetails.cs (this view has CustomerDetailsViewModel as datacontext and this set automatically by Caliburn.Micro)
View: CustomerInfo.cs (now this is the view where I want to share CustomerDetailsViewModel, which could have some data already modifed via CustomerDetails view)
I am currently using NavigationService to navigate to CustomerInfo view. Is there any way to pass the reference of current viewmodel to the view which user is navigating to in caliburn.micro?
Thanks in advance
idev
Use the attached property cal:Bind.Model="{Binding}" to bind the view to the view model.
See http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions "View First" section.
Alternatively you can also look into the cal:View.Context="MyContext" attached property as described here: http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition "Multiple Views over the Same ViewModel" section.
Add a property or two to your App.xaml.cs. What ever you put in here will persist throughout the lifetime of the application (keep in mind that tombstoning will cause this property's value to be lost though). If you want to pass a ViewModel then setyour associated property in App.xaml.cs to the view model and then when the new page loads have it read from that same property.