我有一个带有 ComboBox 的 DataTemplate 的列表视图。我希望 ComboBox 看起来像标签一样平坦,直到用户真正想要更改值。我之前有下面的例子,但我改变了一些东西,现在它不再工作了,我不知道为什么。
IsMouseOver 属性似乎无法正常工作,因为它仅在鼠标位于控件边界时才设置。
我该怎么做才能使这项工作正常进行?
这是一个片段:
<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>