Default DataGridComboBoxColumn ControlTemplate - wpf

Without bothering you with what I intend to do, could someone kindly point out where I can get the default DataGridComboBoxColumn ControlTemplate. I am sure there must be a Control Template or some kind of style that targets a DataGridComboBoxColumn, otherwise how did Microsoft build the DataGridComboBoxColumn.

Without bothering you with what I intend to do
I think it is not so unimportant, because of these advises on MSDN page DataGridComboBoxColumn Class:
Represents a DataGrid column that hosts ComboBox controls in its
cells.
and
If you want to use other controls in your DataGrid, you can create
your own column types by using DataGridTemplateColumn.
For styling (also ControlTemplate!) of ComboBox you can use ElementStyle and EditingElementStyle properties of DataGridComboBoxColumn.
Default template for ComboBox you can find here: ComboBox Styles and Templates
Small example:
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<TextBlock Text={Binding SomePropertyOfYourRowDataContext}/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridComboBoxColumn.ElementStyle>

Could someone kindly point out where I can get the default DataGridComboBoxColumn ControlTemplate.
A DataGridComboBoxColumn is not a Control and hence it has no ControlTemplate.
It creates a ComboBox in its GenerateEditingElement method and it is this ComboBox that you see when the cell of a DataGridComboBoxColumn is in edit mode: https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/DataGridComboBoxColumn.cs,90924e66a85fbfa4.

Related

DataGrid AutoGenerateColumns ErrorTemplate

I'm trying override default DataGridTextBoxColumn ErrorTemplate. I can do this if I manually set DataGridTextBoxColumn but I must using autogeneratecolumns, then I can't style this... Any ideas?
Datagrid default cell ErrorTemplate
Thanks..
What you get when you're editing a cell in a datagridtextboxcolumn is a TextBox.
I don't have something set up I can test this with, but it won't really fit in a comment.
I would think if you just apply a style to textbox then that will work.
Put a style in the Datagrid.resources:
<Style TargetType="TextBox">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
And, of course, whatever template you want to use in there.

how to set List item Height,width and Border for ListBox in wpf

I need to set Height,Width and Border Color for Each list items in the Listbox. In the event that I set Setter Property
it's setting for entire listbox. Be that as it may, I need to set every last rundown thing. Any one help me.
here's my code:
<ListBox x:Name="lbOne" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown"
HorizontalAlignment="Left" Margin="12,29,0,12" Width="215"
ScrollViewer.VerticalScrollBarVisibility="Visible" />
Try the following piece of code and let me know if it works for you.
<ListBox ...>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
Also, please refer the followings link for reference.
Stretch ListBox Items hit area to full width of the ListBox? ListBox style is set implicity through a theme
Silverlight 3: ListBox DataTemplate HorizontalAlignment
Probably, refer to the below link for using the ListBox Item properties appropriately.
http://msdn.microsoft.com/en-us/library/cc278062(v=vs.95).aspx

How to change wpf listviewitem background color when its data is using binding?

I'm trying to change listview's row background color for a data binding listview.
From msdn, I know there is ListViewsItem.Backgroud for the color of its background.
But since I'm using data binding for ListView's data source,the type of ListView's item is actually my class type, no longer ListViewItem. So I can't find its Background property.
I guess I missed something, how should I do it?
Thanks
You can set ItemContainerStyle of your listview like below to set any property on item.
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="Red"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
You even change the background depending of dataitem state using triggers in style.

How can the ViewModel drive a ControlTemplate?

I have the problem that parts of the TreeView Controltemplate need to change depending on the state of the bound (ItemsSource) ViewModels. For example the little expander icon needs to be exchanged with a different drawing based on each items ViewModel state. Additonally based on the state of each ViewModel the child items need to be arranged horizontally instead of the default vertically.
It sounds like you have to customize ItemsContainerStyle, not ControlTemplate. For example, if you want to mark TreeViewItem as selected whenever underlying ViewModel is selected, you can use the following style:
<TreeView ItemsSource="{Binding ...}
...>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<!-- IsSelected is a property on ViewModel item -->
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
<Setter .../>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
If Binding doesn't suit you, you can use Converters, Triggers in Style or ControlTemplate. Furthermore, you can also use triggers in DataTemplates.
PS: Wrote the code from head. May have a typo.

silverlight 3.0 grid row selector color

is it possible to specify the color for the row selector in silverlight grid
Yes but you need to copy the control template for the DataGridRowHeader control and place it in a Style object in a resource:-
<UserControl.Resources>
<Style x:Key="CustomRowHeader" TargetType="DataGridRowHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="localprimitives:DataGridRowHeader">
<!-- Copy of the rest of the standard controls template -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<UserControl.Resources>
<DataGrid RowHeaderStyle="{StaticResouce CustomRowHeader}" ... >
Now you can fiddle around with the color value and pretty much anything else that is used to render the row selector.
You can probably do this with Blend fairly well if you have it and are familiar with using it. I prefer to copy the template from the documentation. See DataGrid Styles and Templates
No, but it's perfectly possible to subdivide a grid into rows/columns and fill them with rectangles+background or something like that.

Resources