I have created a ribbon (R:ribbon) inside my main window in WPF. And I added a frame to the same window (bottom to the ribbon) and display pages inside the frame according to the buttons click on the ribbon.
1.I have ribboncombobox on the ribbon , I want to get particular value in that combobox and display that value in a page that is display in the frame.
2.Also need to transfer data from one page to another.
This is window based project. Don’t know is this possible to do. If it is possible please guide me with some sample code. If this concept is wrong please let me know how to do this.
Thank you very much.
Have a ViewModel class for the MainView. Create properties for the corresponding data to be transferred and bind them.
Related
Issue: I have a Frame that Frame Holds a pages
That page has a gridview control, I can design the grid, I have connected it to a database.It does not however have the default events of select, and highlight a row so that I can select a record and do what I want with it. Why?
Answer: Although WPF allows you to put a page in a frame controls can only be used in Windows so you have to make a single page application using the one window. You have to make it look like your navigating when all that's happening is your switching out controls in the main window. So a page in a frame really only allows you to show an image because it's static. All research directs you to MVVM pattern. Take a look here: https://code.msdn.microsoft.com/How-to-Build-Manage-and-fdd0074a#content
I need to develop an multipage WPF application. I tried to achieve that by using one Window and multiple Pages. When I need to switch from one to another page I just change Content of main Window to point to that page. I have filling that I'm using wrong scenario because I don't have idea how to reuse XAML code for example an Menu controll, StatusBar and ToolBar for all pages.
You need ContentControl. It changes view based on ViewModel. Place your static elements in one place and in changeable area a ContenControl object.
More here and here.
One idea is you have a PageViewModelBase that implement a base virtual Property and Methods for Menu and StatusBar model and ... Then Each PageViewModel Override proper implementation of PageViewModelBase, Then Window contains Menu or StatusBar that Bind to DataContext of Pages.
I am new to WPF.
I have requirement to create a window (as below. Ignore background color. Just gave color to distinguish different panels). On click on next, center panel (with frame) will load another page/user control. This is working fine.
Now I need to validate data/input of the form when user clicks Next. If everything is fine, next control should load. But I am unable to get controls from frame to Mainwindow.
Can someone please help me on how can I access controls of page/usercontrol from Main Window. I have a label after each control which will show error message if values are not not provided or are incorrect.
If you are using MVVM Pattern, On your next click, you can raise an event from the usercontrol View Model and get some response back to the Main Page's View Model where your Next code resides.
OR
You can access the Usercontrol's Datacontext in Main Page's View Model, Cast it to your Usercontrol's View Model. Take the information and just do your validation.
Hope this will help you...
I am trying to work though the best approach to accomplish the following. Within a page I have it divided into two section. On the left a listbox and the right is empty. (Grid etc). What I would like to accomplish is when an item is selected from the listbox a different user control loads in the right panel. For example if I have three items (one, two three) selecting one would load a red user control, two would load a blue user control and three a green user control.
I was taking this approach since Content Template / Data template selectors are not available in SL. However if anyone has another suggestion I would be grateful for your thoughts.
I'm creating this with MVVM in mind and traditionally I have managed this within the code behind of the user control however I have seen mention of how this could be managed within the ViewModel as well.
Any suggestions or guidance on a best approach is always appreciated.
Cheers
You can bind both listbox selected item and user control visibility properties to the same property in the viewModel.
Then just use a valueConverter for each user control to switch on/off the visibility.
Please tell me if i should elaborate/add a code sample.
I am working on Silverlight project.
I added a custom user control (Say, control1) which has a text box and button to a xaml page (Say, Page1).
Now what I want to do is when users clicks on the button, i want to pass the value in the textbox to Page1 and do something.
So basically, I am looking for a way to pass back a value from child to parent page in Silverlight.
Thank you.
You should look into the Model View ViewModel (MVVM) pattern. It works very well with WPF and Silverlight.
http://en.wikipedia.org/wiki/Model_View_ViewModel
http://karlshifflett.wordpress.com/mvvm/ (lots of good information and demos)
You can do this through binding. Bind the Text value of the TextBox to a string property in your ViewModel and use that property throughout the code.
All the controls within your user control are accessible within your main page. If possible, write the click event of the button within the main page and you'll be able to access any control's property. Hope that work for you.