WPF: Strategy for Creating a Single Item Paged ItemsControl - c#

I am wanting to build a WPF custom control that displays validation errors - one at a time - in a ribbon that goes across the top of the screen.
An ItemsControl or Selector sounds like a potential base class candidate, but my requirement is that only one item is shown at a time and the user will click on forward and back buttons on the ribbon to navigate through the validation errors.
Is it possible to use an ItemsControl in this way? To only show one item at a time?
Is there a better strategy for this?
I appreciate your thoughts and expertise!

This article should cover everything you want to do. The FlipView basically behaves like an ItemsControl and shows one item at a time by providing forward/back buttons.

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.

WPF: How to dynamically create controls and edit controls in code

I have a xaml which contains a tab control (Name="MyTabControl"). I'm a beginner with wpf and in code and I want to dynamically add tab items that I then add a list box to each created tab item. Below is the code I have so far.
ListBox listbox = new ListBox()
TabItem tab = new TabItem()
tab.AddChild(listbox)
MyTabControl.Add(tab)
My issue is that I can't figure out how dynamically create new tabs that also would add a list box to each new tab and the new tabs then added to MyTabControl.
Then, I would want to be able to access each list box control, individually, in each tab to edit the list box content.
How is this done in code? How can i access the created list box controls to edit them?
WPF/UWP and XAML are designed with the MVVM pattern in mind. While you can use other approaches, doing so will miss about 90% of it's power and run into issues at every other corner.
In MVVM this would be simply a mater of Exposing a Collection and having a Tempalte targetting that type. ListBoxes might even have a custom Template system, but using ListBoxes might no longer be nessesary - any container can expose a Collection.
If you plan on learning MVVM, mid to longertem you should learn MVVM. I wrote a short intro a few years back, that should help you going. Help for people not following MVVM is parse on the Forum.
In general, it's a violation of the MVVM principles WPF is built around to build a UI in this way. Instead, consider a solution similar to the one proposed in the answers to this question. They do a good job of explaining both what to do, and why we do it this way.

The best practice to implement custom\user control in WPF

I have a list of custom controls that should look something like this
Before I start to implement them through a custom or user control in WPF (via MVVM), I want to ask if I do everything right. I create a DataTemplate and binding properties I need (these are the numeric values (0.13) in columns) and ItemTemplat'ing it to listview or listbox. Also I'm having an observable collection of viewmodels for these templates and every viewmodel sends some specific numeric data through short intervals from slave device. Also I need this green element to be clicked (just to add a button to a template I guess) and having displayed an additonal window with real time plots. So my question is: Is this the right approach I'm talking about or do I have something wrong? I'm quite new to WPF, so please excuse me. I dont think that it is a great challenge to implement something like this.
I'm rather new to this model as well, however one thing I have found that has helped me with managing multiple View Models has been an IOC Locator. An example can be found here:
http://dotnetpattern.com/mvvm-light-toolkit-example

ListView with TreeViewItems in xaml

I'm pretty new to c#, the first thing that I'm trying to make is a ListView with data bindings which has turned out ok.
I'm now trying to make items have a twist button if the underlying model has any children (like the TreeView). Each of the children will have columns the same as all the top level items.
How would I go about doing this? Is there an already existing control like this? If not would I be better off dressing up a TreeView to look like a ListView, or dress up a ListView to look like a TreeView?
I went down the road outlined in this solution which dresses up a TreeView, but the end result looks pretty awful and the heading is actually just an item, so you lose all the nice column sizing and column buttons that can hook up to column sorting that you get in ListView so that route actually seems like it would be more work.
I noticed the new task manager has a control exactly like what I'm trying to create, I don't know how this made? probably in C though.
Microsoft provides a sample that appears to be what you are looking for. A write-up of the example can be found here:
http://msdn.microsoft.com/en-us/library/vstudio/ms771523(v=vs.90).aspx
When you build and run the example you will end up with something resembling this:
There is a large amount of templating done in the example, so you will be able to make things look the way you want.
What you describe sounds a bit like a TreeListView, and if you google 'WPF TreeListView' you will see some solutions that might be good for you. I have used one from Telerik, but it might be overkill depending on how complicated your needs are.
If you only want one sub-level like the image you attached, you might want to just roll your own using a ListView with a complex DataTemplate for the first column which would show an expander button and a simple ListBox bound to the children items.
Similar to the answer here, except your cell would have a checkbox styled to look like the arrow, the text for the item, and a child ListBox. Then bind the visibility of the child ListBox to the state of the checkbox.

How to design the UI for settings according to different options in C# WinForm?

This is a .NET winform application question.
I come to this design from time to time. A simple form. On top of the form you have a list of options to select. According to different option chosen, the body of the form displays a unique panel of setting detail.
How to design this UI in Visual Studio neatly? I have two ideas. First idea is to have many panels, each panel contains setting controls. In runtime, hide all panels but the one according to the selection of option. In this solution, it is hard to organize the controls of the form in VS designer. You need to set the form big to hold all the panels. Panels are put one next to each other. There are many runtime loading code to write. For example, when loading the form, you need to hide panels, reset the form size. When you pick an option, you need to relocate the panels and show/hide them. Tedious!
Second idea is to use TabControl. TabControl is good because the tabs are well organized for you. You don't need to relocate panels and resize the form. All you need to do in runtime is to select the right tab according to options. One thing, you need to hide parts of the TabControl from user because after all it is not a real TabControl. Hiding the tab buttons of the TabControl is not hard but I find that after that there is always a big gap between the tab area and the following part on the form.
Dose anyone have a decent way of designing the UI? Maybe not using panels or TabControls but some smarter way? If TabControl is used most of the time, how to hide and show the tab parts of the TabControl and how to set the margin and border size of the TabControl so no big gap exists? Many thanks to any answer and suggestion.
When I need to do this, I put each group of controls in its own UserControl, and then I can use something else to switch between them. See, for example, Implementing a paged Options dialog on my blog.
I suggest you create UserControls for each of your "setting details" and when the user selects an option you load the accordant UserControl. You might have to adjust the forms size, but therefore you can easily manage all the "setting details" in your IDE.
Using user control is a good way to solve your problem. But you need set them probably in panels and play with properties "Visible" and "Dock".
You don't need to Dock them at "Fill" in design mode. You can set this property à runtime or when needed.
Hope this help.
Sounds like you need some design pattern.
Why not create a UI factory that returns your UI objects as needed/required?

Categories

Resources