I have a ItemsControl in ScrollViewer and I set ItemsPanel of my ItemsControl to Horizontal StackPanel and i bound it to ObservableCollection of userControls.Now I wanna when user click on icons of open UserControls in my ItemsControl,automatically scrollviwer's offset change to show icon clicked UserControl.( I have a Icon for my each usercontrols)
And also when user open new UserControl ,I wanna my ItemsControl automatically show it ( now when I open a new usercontrol i should scroll my ItemControl to reach it),
can I do this with above controls ,if yes, can you tell me how? If not, I appreciate to tell me which controls should I use controls and how?
Related
In WPF i want to create an custom TabItem which contains other controls.
After creating the TabItem, i want to add it to an TabControl.
The content of the TabItem will be created dynamically.
The TabItem only will be vissible after clicking on a button, and will close after entering the neccesary information.
After closing the tab, there will be no blank space in the TabControl.
I tried with a custum control, an user control and a class which inherits from an TabItem. But none of them does what i want.
Which is the best solution in this case?
You want to set the TabItem content to the UserControl not inherit from TabItem. Also you can bind the TabControl.ItemsSource to a collection of UserControls that would make it dynamic like you want I believe.
I solved my problem.
Instead of crating an usercontrol for the tab, i created an usercontrol with the contents of the tab.
In my case, that's a grid.
After that, i use the customcontrol to fill the tabitem.
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'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 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.