How can I extend width of dropdown of a combo, like Run dialog:
Popup is a part of ComboBox template ("PART_Popup"). Add a Style for Popup to combobox Resources and set appropriate width there.
<ComboBox>
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="Width" Value="1000"/>
</Style>
</ComboBox.Resources>
</ComboBox>
note also that there is a binding for Popup.MinWidth in template so you can't make it too small.
Related
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.
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
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.
In WPF Listbox, I'm confused with these 2 notions:
ItemTemplate and ItemContainerStyle
Can someone explain me more?
The ItemTemplate is for styling how the content of your data item appears. You use it to bind data fields, format display strings, and so forth. It determines how the data is presented.
The ItemContainerStyle is for styling the container of the data item. In a list box, this would be a ListBoxItem. Styling here affects things like selection behavior or background color. It determines style and UX of the display.
The MSDN page for ItemContainerStyle, linked above, has a pretty good example showing some differences:
<!--Use the ItemTemplate to set a DataTemplate to define
the visualization of the data objects. This DataTemplate
specifies that each data object appears with the Proriity
and TaskName on top of a silver ellipse.-->
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="18"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataTemplate.Resources>
<Grid>
<Ellipse Fill="Silver"/>
<StackPanel>
<TextBlock Margin="3,3,3,0"
Text="{Binding Path=Priority}"/>
<TextBlock Margin="3,0,3,7"
Text="{Binding Path=TaskName}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<!--Use the ItemContainerStyle property to specify the appearance
of the element that contains the data. This ItemContainerStyle
gives each item container a margin and a width. There is also
a trigger that sets a tooltip that shows the description of
the data object when the mouse hovers over the item container.-->
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Control.Width" Value="100"/>
<Setter Property="Control.Margin" Value="5"/>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="Control.ToolTip"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=Content.Description}"/>
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
The ItemContainerStyle just a wrapper for the DataTemplate so that a common item style can be applied to different data layouts.
Also, from this answer to "DataTemplate vs ItemContainerStyle":
You can do all your styling in the ItemTemplate but the ItemContentStyle has VisualStates which control the Opacity on mouse over/disabled/selected etc.
If you want to change those opacity state changes, or if you want any Container shape other than a rectangle, like a triangle for example, then you'll have to override the default ItemContainerStyle.
I have a control which has a combobox and this control is placed in a window. When I click on the dropdown of the combobox the width of the items are going out of the width of the window.
The width of the combobox in the control are set as minwidth=600 and maxwidth = 600.
If I change the width here, all the places where this control is used, its width will be affected.
Can someone help me?
You can specify the dropdown width (and other properties ... MaxWidth) by defining a ComboBoxItem style and setting your ComboBox ItemContainerStyle to it.
<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="600"/>
</Style>
<ComboBox ItemContainerStyle="{StaticResource ComboBoxItemStyle}" />