I have a usercontrol in my Silverlight 5 Application. This UserControl can be placed on any other control (perhaps on a TabItem, a Panel etc.). I does now have to determine, if the UserControl is visible to the User. This should only be true, when the UserControl or some region of it are visible to the user. This sould be false for example, when the UserControl is on a TabItem which is in background or the UserControl is on a collapsed panel etc.
Can I get this information out of the VisualTree?
Thanks for any hints.
Setting the visibility can be done with the code below:
MyItem.Visibility = Visibility.Visible;
Normally, when placing an item inside a tabcontrol, the visibility value of it depends on the active tab, changing tabs will result in seeing the tabs value, while not giving the other tabs values.
Related
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!
I have a usercontrol which is placed inside one panel and some other controls like buttons in another panel. when the usercontrol is active and i move from other controls using tab key, usercontrol gets focus even when the TapStop property for the usercontrol is set to "False".
In another case, when i have the usercontrol placed in the form not inside the panel, usercontrol didnt get focused when moving from other controls using tab key.
Could anyone share me the details why the usercontrol is getting focused when it is only placed inside the panel?
Thanks and Regards,
Amal
I'm making a WinRT application using XAML and I have a control that has a TextBox and a Popup that opens under it when the TextBox get focus.
The Width of the Popup is the same as the Width of the TextBox. This works fine but if I put my control in a ScrollViewer and zoom in the size of the popup doesn't change. I would like to achieve something similar to the standard ComboBox which changes the size of its Popup when it is nested in a ScrollViewer. What should I do?
I know that the popup must be part of the VisualTree but I'm not quite sure how to add it without changing the existing layout.
Thank you
To have the popup be parented in the TextBox you can either modify the template of the TextBox and put it in there (you could subclass TextBox to both add support for your dropdown logic and change the default template at the same time) or simply find the root Grid of the TextBox using VisualTreeHelper. By default TextBox has a Grid at its root, so you could get that and add the Popup to its Children.
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 create an user control that has some textbox and buttons.the problem is when I use tab to traverse in My form when my usercontrol get focus the focus go inside of user control and buttons insid if it would focus.How I can simply go to next control after my user control not inside it?
thanks
If the controls have Focusable CanHaveFocus TabStop sort of properties, set them to false.
Also set the TabIndex properties of those controls to 0. I'm sure that the controls will be ghosts in terms of getting tab focus.
Set TabStop property on your custom user control elements which you want to exclude (eg. your button) to false.