Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After many different attempts to solve this problem, I finally came to a solution that works.</p> <p>I created a style for the ListBoxItem that set the TemplateControl and set the VisualStates for the MouseOver, Selected, and UnSelected states.</p> <p>Here is the XAML code solution to the problem:</p> <pre><code> &lt;Window.Resources&gt; &lt;Style TargetType="ListBoxItem" x:Key="ListBoxWithNoSelection"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="ListBoxItem"&gt; &lt;Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup x:Name="CommonStates"&gt; &lt;VisualState x:Name="Normal" /&gt; &lt;VisualState x:Name="MouseOver" /&gt; &lt;VisualState x:Name="Disabled" /&gt; &lt;/VisualStateGroup&gt; &lt;VisualStateGroup x:Name="SelectionStates"&gt; &lt;VisualState x:Name="Unselected" /&gt; &lt;VisualState x:Name="Selected" /&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;x:Array x:Key="NumberOfPicturesOptions" Type="sys:Int32" xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt; &lt;sys:Int32&gt;10&lt;/sys:Int32&gt; &lt;sys:Int32&gt;15&lt;/sys:Int32&gt; &lt;sys:Int32&gt;20&lt;/sys:Int32&gt; &lt;sys:Int32&gt;25&lt;/sys:Int32&gt; &lt;sys:Int32&gt;50&lt;/sys:Int32&gt; &lt;sys:Int32&gt;100&lt;/sys:Int32&gt; &lt;sys:Int32&gt;150&lt;/sys:Int32&gt; &lt;/x:Array&gt; &lt;x:Array x:Key="QualityOfPicturesOptions" Type="sys:Int32" xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt; &lt;sys:Int32&gt;5&lt;/sys:Int32&gt; &lt;sys:Int32&gt;6&lt;/sys:Int32&gt; &lt;sys:Int32&gt;7&lt;/sys:Int32&gt; &lt;sys:Int32&gt;8&lt;/sys:Int32&gt; &lt;sys:Int32&gt;9&lt;/sys:Int32&gt; &lt;sys:Int32&gt;10&lt;/sys:Int32&gt; &lt;/x:Array&gt; &lt;myProj:PictureOrders x:Key="Orders" /&gt; &lt;/Window.Resources&gt; &lt;ListBox x:Name="OrderListings" DataContext="{StaticResource Orders}" ItemsSource="{Binding PictureOrders}" SelectedIndex="0" ItemContainerStyle="{StaticResource ListBoxWithNoSelection}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Expander x:Name="PhotoOrderExpander" Content="{Binding}" Header="{Binding OrderName}" IsExpanded="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"&gt; &lt;Expander.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;DockPanel Margin="25,5"&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label VerticalAlignment="Top" Content="Order Name" /&gt; &lt;TextBox Text="{Binding OrderName, ValidatesOnExceptions=True}" VerticalAlignment="Top" MaxLength="50"/&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="NumberOfPictures" /&gt; &lt;ComboBox ItemsSource="{Binding Source={StaticResource NumberOfPicturesOptions}}" SelectedItem="{Binding Path=NumberOfPictures, ValidatesOnExceptions=True}" /&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="Quality Of Pictures" /&gt; &lt;ComboBox ItemsSource="{StaticResource QualityOfPicturesOptions}" SelectedItem="{Binding Path=QualityOfPictures, ValidatesOnExceptions=True}" /&gt; &lt;/DockPanel&gt; &lt;DockPanel DockPanel.Dock="Top"&gt; &lt;Label Content="Comments" /&gt; &lt;TextBox Text="{Binding Comments}" /&gt; &lt;/DockPanel&gt; &lt;/DockPanel&gt; &lt;/DataTemplate&gt; &lt;/Expander.ContentTemplate&gt; &lt;/Expander&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>-Frinny</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload