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.
Related
i'm using an ItemsControl to generate a list of controls based on my model.
When looking at the visual tree, i noticed that each of the rendered control is wrapped in a ContentPresenter. The controls that are added are a 3rd party control and are designed to display a splitter between each control if they are siblings..this allows a user to size each control. For example the following will show a splitter between each of the controls at run time.
<StackPanel>
<3rdPartyControl />
<3rdPartyControl />
<3rdPartyControl />
</StackPanel>
When using an ItemsControl, each of the 3rdPartyControl are wrapped in a ContentPresenter, and thus no splitter is shown. I have tried various ways to try and solve this problem but unable to get this to work unless i write code behind to add each control rather than rely on Xaml.
Does anyone know of a way to replace the contentpresenter completely (in my case with 3rdpartyControl)?
Thanks
In order to replace the ContentPresenter you could derive from ItemsControl and override the GetContainerForItemOverride method to create a specialized container control.
ListBox for example overrides this method to create a ListBoxItem as container for a new item object.
That's true, every element that you add to ItemsControl is wrapped with ContentPresenter, you can find more details about it in the greate series of articles from dr.wpf ItemsControl a-z
One way I would suggest to try is to change ItemsControl to ListBox and make ListBox act like ItemsControl. In this case you can re-style/re-template ListBoxItem and replace ContentPresenter with your control. You would also need to stop selection support. Here is ListBox style that you need to change.
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.
I have created a data template for a data class. The width of the grid created by the datatemplate is bound to a property in the data class, ie, the size of the control matters.
I am creating a list of the data class objects, and adding them to an items control in MainWindow.
Update:
I would like to line up the controls from the data list one after another, and not have them resize.
Example:
[---------box1----------][--box2--][------box3-----]
each are the same data template type, and different widths. Perhaps I shouldn't be using itemsControl, but I am unsure of what other control to use to achieve this.
Any help would be much appreciated. I can post XAML
Can you post some XAML.
It can depend on the HorizontalContentAlignment of the ItemsControl or the style of your ItemContainer/ItemPanel.
I have a DataGrid that is showing some data via a PagedCollectionView with one group definition. I have created a Style for the corresponding DataGridRowGroupHeader under which I have added a ControlTemplate containing an additional TextBlock and a spacing Rectangle. I would like to bind the widths of these controls to the widths of particular columns, but I am struggling to get this working. I would also like to bind the Text property of the TextBlock to a value.
I tried binding the widths via the Width property of a Rectangle in resources but this didn't work (possibly because the Rectangle was never drawn and therefore didn't calculate it's layout).
However, I believe both sets of bindings can be performed with some use of one or more ValueConverter implementations, but I was wondering if there was a better way. Can any of this be achieved through the definition of a ControlTemplate?
After some trial and error I was able to customize my row group headers. The key to unlocking the solution involved both the RowGroupHeaderStyles property and the LoadingRowGroup event on the DataGrid.
By defining one or more styles for the groups, I was able to customize the control template to include additional named elements. I then used the event to gain access to those elements and either set or bind the relevant values to show the information I required. The only stumbling I had related to binding the size of controls, which I eventually worked around by saving a reference to each row and setting those sizes when it was necessary to refresh them rather than relying on bindings. This may be specific to my project so your mileage may vary.
Update
JDM asked how you get the controls to perform binding etc. in the LoadingRowGroup event handler. You can get the row header from the DataGridRowGroupHeaderEventArgs.RowGroupHeader property of the event arguments and then use the VisualTreeHelper to get the child controls of the header. Once you have the controls, you can bind to them in code as you would any other control.
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.