The following illustration shows four buttons whose Content property is set to one of the following: A string. A DateTime object. A UIElement object. A Panel control that contains other UIElement objects. Four buttons with different types of content. A ContentControl has a limited default style.
First I bag your pardon for my por English. I begin to develop C# WPF application using Catel MVVM framework now.
My application must have: Main Window, 5 views done as UserControls and 5 buttons (on toolbar in MainWindow). These buttons are for switching among views.
![Wpf Contentcontrol Set Content Wpf Contentcontrol Set Content](/uploads/1/2/5/4/125440727/718656727.png)
Each button must turn on corresponding view and turn off the previous displayed view in Main Window. For example if “Display Flowmeter Status View” button is pressed and “Field Settings” view is being displayed in Main Window that moment then “Field Settings” view must be turned off and “Flowmeter Status” view must be displayed in Main Window instead of. I’ve read your “Switching between Views/UserControls using MVVM” article but I’m a green tyro in Catel. I fear that approach described in your article doesn’t match to Catel. Please tell me if using a your DataTemplate approach for switching among views is fit to my case. Your help will be appreciated highly. Hi Rachel, Thank you very much for this great article, I found it very informative and understandable.
I would like to ask you a question about a specific scenario: Lets say that, further your example, is very large control and is needed to kept alive (cached) in the memory. The problem is that every time we set the property of WorkViewUserControl ViewModel (WorkViewModel), the WPF automatically initializes a new instance of WorkViewUserControl, so it very Ineffective. I would like to know how the best practice to achieve it. Hi Rachel, I am getting a bit confused with the way this might work.
I have a SQL Server database that contains all of the data. My WPF application is essentially a viewer, but I’d like it to become a full CRUD application. The tables in the database are relational, and I had been using stored procedures called by TableAdapters to fill the DataSource layer and bind that to the UI elements. Can you explain or point me to an explanation of this basic diagram in terms of MVVM and the VS IDE? Will I use a DataSet like the IDE seems to want, or does this violate the MVVM? If I use a DataSet, should it mimic the Database, so that the a datatable that is the result of a left join can be two way? Am I missing something entirely?
Thanks for the great blogging, Paul. Hi, I want to open a custom dialog box or some child window if I selected an item in main window and want to transfer control to dialogbox/child window.
I searched a lot on web but I could not find any straightforward approach. I am working with WPF and MVVM light tool kit. I am quite new in this field. In main window, I have list of items and I want to open a detailed version of selected item in dialog box / child window and I want to edit my item in dialogbox / child window. I want to have Save and Cancel button on dialogbox / child window. Can you suggest me right way of doing this kind of task.
Hi All, I have a UserControl that is 'hosted' in a ContentControl. I need to access the ContenControl height from my hosted UserControl. That is I set the Content property of mainContent to my UserControl.
I need to access some properties of 'mainContent'. In fact I want to acces to Height of this content control. In the child UserControl I have tried: ContentControl c = this.Parent; But it returned null. Can you help me????
Thanks in advance. You also need to make sure that you are looking at the ActualHeight and ActualWidth properties of the content control. Not just the Height or Width properties. Height/Width will be the same both before and after setting the UserControl as the content of your ContentControl. These don't reflect the actual rendered size of the control. If ActualHeight/ActualWidth are not yet set, then UpdateLayout should certainly cause the layout pass to occur (unless you are already in the middle of a layout pass or a recursion loop is detected). If ActualHeight/ActualWidth are not accurate after the call to UpdateLayout, you may need to BeginInvoke your code at Loaded priority to ensure that a layout pass truly occurs first.
I'd rather advice you always keep Reflector near you. If you have any issues you can always walk through the logic detecting the key points. ContentControl has a dependency property changed callback for the Content property. Static method OnContentChanged(.) is used for setting the readonly property 'HasContent' and add the newly assigned value as a logical child. If you are dealing with constructor why not simply provide the parent element in the UserControl constructor if you need accessing something from the parent. Guess it will be fair enough. Because the control's construction and content control logical tree manipulation occurs in different time intervals.