I have a listview with a DataTemplate that has a ComboBox. I want the ComboBox to look flat like a label until the user actually wants to change the value. I had the example below working before, but I changed things around a bit, and now it doesn't work anymore and I'm not sure why.
The IsMouseOver property does not seem to be working correctly, as it only gets set when the mouse is right at the border of the control.
What can I do to make this work correctly?
Here is a snippet:
<CollectionViewSource x:Key="AccountCategories" />
<ControlTemplate x:Key="FlatCombo" TargetType="{x:Type ComboBox}">
<ContentControl
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="4,3,3,3"
/>
</ControlTemplate>
<Style TargetType="{x:Type ComboBox}" x:Key="DropDown">
<Setter Property="OverridesDefaultStyle" Value="False" />
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsFocused" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Template" Value="{StaticResource FlatCombo}" />
</MultiTrigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="Category">
<ComboBox IsSynchronizedWithCurrentItem="False" Style="{StaticResource DropDown}"
ItemsSource="{Binding Source={StaticResource db}, Path=Categories}" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding Path=Category}" />
</DataTemplate>
</Window.Resources>
<Grid>
<ListView Margin="0,110,0,0" Name="lstCategories" ItemsSource="{Binding Source={StaticResource AccountCategories}}" Grid.RowSpan="2">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Category" Width="100" CellTemplate="{StaticResource Category}" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Balance}" Header="Balance" Width="100" />
</GridView>
</ListView.View>
</ListView>
I took the code you provided, supplied some data for the collections, and it worked just like you wanted it to. I would suggest using Snoop to look to see if there are any other elements consuming the events you expect the ListView to handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With