"Correct" Way to Show New Controls in WPF - c#

I'm designing a small helper utility with a simple UI. I'm working off the following mockup:
The execution flow is meant to be as follows:
User clicks "Other" radio button.
A textbox is presented and user is prompted to write in a response.
My question is: What is the "correct" way to achieve the UI change from the picture on the left to the picture on the right? My options seem to be either create a unique window for each, or have all of the controls on the same window and just play with the visibility of the controls.

There is no "correct" way really. It all depends on your requirements.
If you want the new screen to show up in a new window, then create a new window. If you want it to show up in the same window and simply replace the previous screen with the radiobuttons, then toggle the Visibility property of the individual controls or the parent Panel, preferably using a view model that has either bool or Visibility source properties that you have bound to in your view.

Related

How to achieve Oculus UI in .Net WPF

I am trying to achieve this look&feel in WPF.
It basically acts like a TabControl, with the tabs on the left (vertically)
The right side of the window completely changes depending on which item you have clicked on the left "nav bar":
Oculus UI
What I did:
I started doing a Custom Control. A grid with two columns, a StackPanel in the left column in which there will be a clickable button/label for every menu entry (vertically of course). A Property MenuEntries which is a List<string>.
How do I get the control to add a "tabpage" (a grid/canvas?) programmatically for every MenuEntry the user adds at design time?
How can I achieve the behavior of the TabControl during design time, i.e. the content on the right side changes as soon as the user clicks an item on the left (in the designer/editor)? (kind of like the TabControl itself?)
Is this the right approach or would you do that completely differently?
Yes, you can use TabControl for that, just set TabStripPlacement="Left", (some more details)
The whole rest: colors, margins etc is set via styles.
Also, to save you a lot of trouble, use MVVM (with some framework for WPF) for that. Set ViewModel collection as ItemsSource for the TabControl.
Then, when you select one of the tabs, the control will display the view for the selected VM.
DO NOT set TabItems in xaml for each tab, this is wrong way to go in the long run.

Switching between to Forms within a single window

I want to change my form 1 into form 2. I don't want it to open a new window but keep it in the same window and then be able to go back and forth when I press the Next key or back key. Is the only way to do this by Individually hiding each button and picture?
You might want to consider a different approach.
You can't change one type of form into a different type of form. The closest option would be to close or hide the first and show the second at the same location on the screen.
However, you could approach this differently. Instead of putting your buttons and logic into a form, you could place everything into two UserControl instances, and just change which user control is visible within a single form.
You can use panels, group boxes, TabControls, etc. to group common controls together. When you want to switch between different "screens", you can hide or show the group control by setting the visible property and calling BringToFront(), and it will hide/show all the controls on that group control.

How do I create a Tab Control with no Tab Header in Windows form?

I have created a Windows form using a Tab Control, but it has a header with it. I want to hide it. I am not able to do it using any properties of the Tab Control. Is there any property defined for hiding the tab header for the Tab Control without going through the code?
Use following code to hide the tabs or set these properties in design.
tabControl.Appearance = TabAppearance.FlatButtons;
tabControl.ItemSize = new Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
You want the tab panels without the feature allowing a user to switch between them, so I suppose you want to create few separate sets of controls to be shown to the user one at a time. You can achieve this in several ways (you can choose one of them if you find it appropriate in your case):
Use several Panel controls instead of several tabs in the TabControl, however, it would be hard to work in the designer, because all the controls would be visible
Use different Forms instead of tabs to keep the layout parts separated. It can be ok, but you may not want to use multiple Forms, so it depends on a specific case.
and finally, the suggested solution:
Encapsulate each set of controls in a UserControl. This allows you to keep each layout separately, so you can easily design each of them without the other controls getting in the way ;). The the code handling each of the layouts would also be separated. Then just drag those controls in the Form and use set their visibilities appropriately to show the one you want.
If none of those suggestions work for you, let me know, so I can look for other possible solutions.
It's more easy as you think, you just drag the panel's window upper, so will be outside of the form.
Use DrawMode: OwnerDrawFixed will hide TabPage header text DrawMode : OwnerDrawFixed
Another way to achieve the same (or similar) is: You can remove tabs from TabControl.TabPages collection and then add the tab you want to show.
During the Form initialization I remove tabs (so into the designer I can easily manage them) and in some control event (as button click) I show the tab the user has to see.
Something like that:
// During form load:
ctrTab.TabPages.Clear();
// ......
// During button click or some other event:
if(rbSend.Checked)
ctrTab.TabPages.Add(pgSend);
else
ctrTab.TabPages.Add(pgReceive);
In this way the user can still see the header tab but just as title of controls group, he can't change/switch the current active tab.

What would be the best course of action for display different form in a single Winform?

Here's a screenshot of my application:
Basically, depending on what option is selected I'd like to show another 'content' which can be a buttons, or forms or whatever.
What would be the best choice for this? Using MDI? I'm really new to this type of thing.
This scenario lends itself well to tab pages, as you'd find on a TabControl.
However, since you already have a mechanism for switching between the content, you might prefer to create a series of Panels whose Dock property is set to DockStyle.Fill. When the user clicks the appropriate heading, you simply need to show the appropriate panel and call BringToFront() on it. This is essentially what the tab control does internally, anyway.
Don't forget to use SuspendLayout() and ResumeLayout() appropriately to reduce flicker, which can be a huge problem in WinForms applications, especially when there are lots of controls.
You can position a TabControl where the buttons are not visible and control it from your buttons.

Splitting up/merging windows in WPF

I'm new to WPF but I need to implement following functionality:
I have a window that contains one Grid (might be changed to stack panel or something else). In that Grid I have 2 columns, each of them contains another Grid. Lets call them gridFirst and gridSecond. There is also GridSplitter in first column allowing to resize the columns.
I want to provide a button that will allow to separate gridFirst from this window and display it "as it is" in another window. How do I do that?
It would be nice if the new window had a same menu as the original window without me having to copy-paste (that not a good coding practise) all its code to the new window.
Thanks for answers
It sounds to me like you'd want to create a UserControl and put gridFirst in it. That way you can add your user control to your main grid and your window.
If the DataContext of your control is the same then it should look the same where ever you put it.

Categories

Resources