I have a simple window with two buttons on bottom, when one button is clicked it change the view model of my main window, the name of the content button and the command.
I would like that when user click on the button change this with a loading user control i already have but i'm stacked, i don't know it's something i can implement with xaml or i need some code on my view model.
Any suggestions would be appreciated.
Thanks.
You will need some code on your ViewModel to swap out the Button for the Loading control. You can either do this with binding ContentControls or with a Boolean property to set one to visible and the other to hidden while the loading happens.
Related
In my MainWindow,
I have a button btnMainMenu
I have a user control NavigationWindow
from the user control, I want to change the visibility of the btnMainMenu form the MainWindow. I have tried most of the steps suggested in other posts but none of them seems to work for me.
I tried this line of code but got error.
System.Windows.Controls.Button btn = (this.Parent as MainWindow).Controls["btnMainMenu"] as Button;
I would recommend to please go through some design patterns.
This is not supposed to be a recommended way to get an object and changed the visibility.
Have a view and a view model make some dependency and change some property of view model.
Just for your learning, I can tell you one of the way but definitely would not recommend it in your product.
You can use recursion on the child controls of the parent control till you find out the button control you need.
For an error validation mechanism, I've to be able to "navigate" in my application to one specific pane.
Currently I've one "SelectedNode" and tries to focus the control that is bound to this property(basically, I've an AttachedProperty to set the IsFocus, based on the name).
My issue is that sometimes this page contains tabs. And it appears that the control cannot be focused if it's hidden(not in the active tab).
Is there a way from an UserControl to go up in its visual tree to "activate" all his parent?
I cannot just bind the "SelectedIndex" of my tabcontrol in the viewModel, for a lot of reasons:
The UserControl that has the tab has one sub user control for each tab, so the usercontrol doesn't know what is in which usercontrol
Putting such things in the ViewModel is wrong, the ViewModel should not have to know that it's displayed in tabs or all in the same pane
Thanks!
in windows wpf i want design a left bar menu like this:
when i click on an item, in the right the window change.
With which control can i design this?
Tab bar control?
Or a left dock panel and insert inside it some button? In this case how can I change the window on the right when click on a button?
If each time you click on a button you want to display a different view, you could define each of your views in a separate control and in your main window within a grid declare each view in a DockPanel.
Then by binding the visibility property of each DockPanel you can create the logic in order to display only what you want on each click.
I suggest using a styled ListBox and binding the Visibility property of your content to it. Even better you can also use a styled Tab control.
I am building an application which has an ItemsControl, and my DataTemplate for this contains a ContentPresenter. I am binding this ContentPresenter to a UserControl property of my ViewModel. I would like to be able to allow the user to click a button on the UserControl which then shows that UserControl in a new popup window, and then when closed, it reverts back to being in the ItemsControl.
I can get this to show the UserControl in the popup window no problems, but have no idea how to revert it back to being in the ItemsControl.
Any suggestions for this approach would be greatly appreciated.
thanks
Put simply you should not keep a UserControl (a UI element) inside your "ViewModel". Your ViewModels should hold the State of your UI and not the UI itself. Define two different UserControls for the two parts you want it in but this time Bind them to the same ViewModel properties.
I want to achieve the following hierarchical navigation model in a WPF MVVM application:
ShellView
Page1View
Subpage1View
Subpage2View
Subpage3View
Page2View
...
Meaning that on Shellview, I have buttons to activate/deactivate Page1View and Page2View. On Page1View has buttons to activate Subpage1View and Subpage3View and Subpage1View has a button to activate Subpage2View.
Where should the subpages be displayed ? Should the navigational model map to a view structure exacly ? I mean, I have a ContentControl (named ActiveItem) on ShellView, where Page1View and Page2View is displayed when activated. Should the Subpage1View be displayed on Shell's ActiveItem ContentControl or on the parent view (Page1View) ?
If I should display a subpage on ShellView, then how to activate it properly ? Because the button to activate it is on Page1View not on shell.
If I should display a subpage on the parent view (Page1View), then I must create a ActiveItem ContentControl on Page1View and hide it before it's needed. How ? Also I guess parent view scrollbars could become a problem.
Please advise!
Using Caliburn.Micro 1.3, .NET 4, WPF.
Thanks!
I threw a demo together. I'm not sure if it's exactly what you're looking for. The thing to remember is Screens and Conductors can contain Screens and/or Conductors. So nesting or doing complex screen composition is pretty straight forward.
This example has a ShellView with 2 buttons and a ContentControl. Page1ViewModel also has 2 buttons and a ContentControl.
Clicking Page1 or the Page2 button on the ShellView activates the appropriate Page. The same is true once a Page is activated, clicking on SubPage1 or SubPage2 activates the appropriate SubPage.
https://bitbucket.org/dbeattie/cmwpfnavsample/src
We use sub pages this way:
Subpage itself is shown in a ContentControl that is in page view. So we have shell view that has a ContentControl to show active page and in this active page, there is another ContentControl to show Active sub page.
We show list of current page's subpages on the shell view itself (because of layout), so we have ItemsControl that is bound to ActiveItem.Items (provided the ActiveItem is page inherited from Conductor).
So we simply use ItemsControl to choose which page or subpage is the currently active and then use ContentControl to show it. Note that selected subpage is shown through its parent page view.
But basically, it is up to you whether you show subpages directly on shell view (ContentControl bound to ActiveItem.ActiveItem) or use another way.
Although subpages are not included, Coproject sample application might help you. I plan to make it more complex and add subpages later.
ad 2. I don't think you need to hide the ContentControl -if no subpage is selected, it will be empty. Nevertheless, if you want to hide it, I'd suggest using of ValueConverter (from object to Visibility, if object == null then Visibility.Collapsed, otherwise Visible) and bind the ActiveItem ContentControl's Visibility property to ActiveItem again.