Tab navigation in WPF grid view - c#

I have designed a wpf page. But I not able to set Proper Tab Navigation on it. Controls (Specialy gridview) on the page are not following tab index.
In my Gridview,there is textbox ,and i want to set the tab navigation on it.Any idea....
Thank you.

Tabbing does behave strange in wpf due to the single tab scope of the ui-tree. You could perhaps try to set is IsTabStop property to ensure that wpf registers the tabstop.
Remember that for complex ui's with embeded layout elementsit might not be a bad idea to bind the tab-navigation to that of the container control.
have a look at this post: WPF Tab Key Navigation
Rachel explains the problem quite elegantly.

Related

How to activate all the parent(i.e. one tab) of a UserControl in WPF

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!

C#, WPF, MVVM, Creating a viewmodel for message dialogs/confirmation dialogs?

I am not using anything other than a simple WPF application project in visual studio. I've implemented an mvvm application.
I want to display a list of content changes made by a user. I have a main window view model and it currently just builds a strings with changes. I have objects that I can reuse to display their properties (the content).
Currently, I use a MessageBoxResult to show a really long string with the changes. This is a terrible design (I know), but I couldn't really find an answer to what class a regular wpf project has that would allow me to achieve what I want.
I know there is a popup class I can use. In practice, which is better-- another view model for the dialog, or a popup?
Can anyone provide a simple example of one of the two approaches?
Thank you in advance for your response.
What I've done in the past is have a simple Border control, and inside of a TextBlock and whatever Button controls I need. I bind the TextBlock.Text to a public string property named "MessageBoxMessage" which calls OnPropertyChanged(). I bind the Command of each Button to a separate public ICommand which specifies what action to take in the view model when the button is clicked. I then bind the visibility of the Border control - which contains all of the other controls I mentioned - to a Visibility property.
When I want to show a dialog, I set the MessageBoxMessage to the message I want to show, makes sure the commands are set properly, and then set the Visibility on the Border to Visibility.Visible. This shows the box (border), message, and buttons.
You can even implement a semi-transparent rectangle underneath the border (over the rest of the form) that you set to visible at the same time. This will give you the nice "form dimmed" effect and also block the normal form controls from being clicked. A general note - for this to work, these controls need to be at the very bottom of your XAML as the z-index among controls at the same level is inferred from their placement in the XAML - lower in the code is top level on the form.
Let me know if you have any questions about implementing this if it sounds like what you are looking for.

WPF Design Time 'Page' Switching

I've written a custom WPF menu control (similar to a tab control, I suppose) using a ListView to hold the headers, which then can be clicked to switch to the appropriate page. The problem with this is, when I'm coding up the XAML for windows that use the control I can't see anything past the first page in the designer view.
Is there a way to let me switch the view within the Visual Studio designer?
If your ViewModel has something like a SelectedTab property that is bound to your custom menu control's SelectedItem dependency property, then you could change your design-time data (or your design-time ViewModel) to make that tab selected by changing the SelectedTab property appropriately.

Creating a reusable interface element in WPF

I'm developing a WPF application in C# and was thinking about implementing a custom UI element accross various windows.
I would like to have a minimized tray (only about 4px visible) that expands after clicking on an icon next to the tray. The expanded version would show all controls and would minimize when I click the icon again. I created a quick HTML concept to clarify things.
I know I could put a stackpanel and button in my application and making both of them move up when I click the button, but then I would need to duplicate the code a lot.
Though I'm experienced with C#, I'm fairly new to WPF interface development/templates, but I'm sure there has to be a way so I can use that UI element accross my application without needing to copy/paste a lot of lines of code in my form class file.
I hope someone can help me, or at least point me in the right direction.
There are three ways to customize your elements.
1 If you only need visual modifications you can use styles to change the appearance of the .net default controls. You can even override / extend the default templates.
2 If you want custom logic in a control you can create a custom control. The framework brings a lot of "primitives" to build upon. Examples are ContentControl or HeaderedContentControl. Say you want to build a custom expander control you can inherit your custom control from HeaderedContentControl which provides you with Header and Content properties and you just have to implement the toggling logic yourself.
CustomControls are a good choice if you want to build basic functionality which can be used throughout your application. They can be themed/styled depending on the use case, too (see 1).
3 If you want to compose different controls into one control you can create a UserControl. User controls are composed using XAML. Most top level controls are user controls driven by a view model.
Your case can be build using a Popup and ToggleButton or an Expander.
The decision depends on the desired behavior. If you want the opened panel to move following content down you need a expander. If you want a dropdown like functionality you need popup.
If you use a popup just bind the IsPopupOpen Property to IsChecked of the ToggleButton and set PopupStaysOpen = false to wire the button to your popup.
If you use an expander control you should create a style which can be applied to all equal expanders in your application to minimize the required XAML in each view.
How about using Expander Control?
There's a control called an Expander that is perfect for this. You'll have to style it to look like you want, however it has the functionality you want built-in.

WPF MVVM UserControl Binding to create a Wizard UI

I m working in a WPF MVVM Project and I am using one Wpf Window. In this window i have a space for one usercontrol and two buttons next and back. When i click the next button I want usercontrol1 to be replaced with usercontrol2. etc.
Sounds like you're trying to create a wizard-style user interface.
This Code Project article may help. And right here is a good place for getting started too.
You can have Wizard user control which is binded to WizardModel, In the Wizard control put ContentPresenter control, and bind it to WizardModel's WizardPage property. And by changing that WizardPage property, you can change wizard page from model.
Hope this helps, here used the same mechanism for changing views

Categories