Extending TabControl and TabItem - c#

I am just trying out extending TabControl and TabItem for fun; including providing custom styles. I am creating the ExTabControl programatically, and adding several ExTabItem(myDataObject) to the tabcontrol. myDataObject has several properties, like "Title" and "Editor." Editor is of type UIElement.
What I am struggling with is how do I bind the Editor property to be the tab panel's content?

Bind the tab item's content property to a control or another property.

Related

Custom tabitem in WPF

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.

Multiple pages in a single window C# WPF

Is there a control that allows to choose data, that should be in it? For example: red one - static page, blue is dynamic, below are buttons that allow to switch pages in dynamic part.
I use the dockpanel suite for this:
dockpanel suite
This contol is designed to mimic the vs.net tabs.
Try using a ContentControl databound to a property on your UserControl. Change the property when you want to update the content. Ensure that the property is either and DependencyProperty or that your user control implements INotifyPropertyChanged.
http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx
This is achived by using DataTemplates. You just bind the SelectedItem of the "red" control (e.g. a ListView) to the Content of the "blue" Control (it should be a ContentPresenter).
You add DataTemplates to the Resources accessable by the "blue" control which will then display different content depending on the underlaying class/data.

SelectorRegionAdapter and TabControl: How to correctly use it?

I am using Prism 4 and I am trying to figure out how to use a TabControl as a region. The documentation says that SelectorRegionAdapter would be used as the region adapter for it. My main questions are about adding the views.
How does the adapter determine the header for the view's TabItem?
How can I control what the TabItem's header would be?
The adapter does NOT generate a header for the TabItem. The UserControl view becomes the TabItem.Content. To generate the header, you have to create a Style and set the Header there in relation to the View under the Content property. Then you bind this style to the TabControl.ItemContainerStyle property on your tab control. When you add views to the Region that is bound to the TabControl, a TabItem is created, using the style specified in the ItemContainerStyle property, setting the Header as specified in the Style.

Binding to ObservableCollection from Custom Control

I have a custom control with an ObservableCollection...
In my Generic.xaml, I have the control template defined there and I would like to bind the ListBox there to the observablecollection of its own custom control (INotifyPropertyChanged implemented), which is different than normal since we're not binding to the view model.
Is this possible?
If you want to bind a control in a control template (listbox in your case) to an object in the custom control (ObservableCollection in your case), you should define the object as a dependency property in the custom control and then use 'TemplateBinding' to bind to the object in the control template.
I am however wondering if its indeed a custom control that you want and not a user control.

Click-to-edit in Silverlight

Is there a way to make a "click-to-edit" control in silverlight? I've got some items that
will be displayed in a treeview control, and I would like the labels to be editable directly in the treeview.
Anyone know how to do this?
Very easy actually. I have implemented many forms with such a swapping mechanism.
You could do this using a Converter and do a simple BooleanToVisibility conversion on an IsEditable property that exists on the entities that you bind to your TreeView. Within your TreeView ItemTemplate just bind the TextBlock in such a way that it is Collapsed whenever the IsEditable property is true and bind the TextBox in such a way that it is collapesed when IsEditable property is false (and vice versa).
If you wanted to build a custom ClickToEdit control you would need to do the following:
Create a class that inherits from ContentControl
Expose a new dependency properties of type DataTemplate: one called EditableTemplate.
Add a MouseLeftButtonUp event handler inside your OnApplyTemplate to listen for the click.
Change the active content template to be your EditableTemplate on the click event.
Change the template back when the control loses focus.
Now to use your custom control inside TreeView:
Override your ItemTemplate for your TreeView
Put your custom ClickToEdit control inside there
Implementing a custom control would allow you (or other developers) to easily specify what control they wanted to use as the content editor. For example, they could specify a NumericUpDown or a DateTimePicker instead of just using a TextBox.
Check out DataForm in Silverlight 3. It has similar functionality but the switching of the editable vs. read-only is not done by a click.

Categories