いくつかの要素が選択され、マウスがその要素を乗り越えるときに、要素の色を変更しようとしています。私の最初の試みでは、ItemsControl
と境界線を使って色の変更を有効にしていますが、これはマウスの色の変化を私に与えていますが、ここに示すようにIsFocussed
を選択するためにどのプロパティをトリガーする必要があるかはわかりません正しくありません:ボーダを選択することはできますか?または、リストボックスの継承を解除する方法を教えてください。
<UserControl x:Class="Crp.CodePlusTeamExplorerSectionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Crp.ViewModels="clr-namespace:Crp.ViewModels"
mc:Ignorable="d"
d:DesignHeight="250" d:DesignWidth="300">
<UserControl.DataContext>
<Crp.ViewModels:RelatedViewsViewModel/>
</UserControl.DataContext>
<Control.Resources>
<Style x:Key="styleWithTrigger" TargetType="Border">
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#3E3E40" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="#007ACC" />
</Trigger>
</Style.Triggers>
</Style>
</Control.Resources>
<ItemsControl Name="RelatedViewsICtl" ItemsSource="{Binding RelatedViews}" MouseDoubleClick="RelatedViewsLB_MouseDoubleClick">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Name="border" VerticalAlignment="Stretch" Height="23" MinHeight="22" Style="{StaticResource styleWithTrigger}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="" Margin="1"/>
<Image Source="Resources\Review.png"/>
<TextBlock Text="{Binding Path=Id}" Margin="1"/>
<TextBlock Text="-" Margin="1"/>
<TextBlock Text="{Binding Path=Name}" Margin="1" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
私が試した他の選択肢はより良いアプローチのように思えるが、リストボックスが正しいプロパティを継承から以内に私の要素を停止し、私はどのようにわからないよListBox
、これを変換することですこれを修正する
:
その後、
ListBoxItem
コンテナのスタイルを設定することができます。 "リストボックスは、正しいプロパティを継承することから自分の要素を停止させる" - このステートメントを明確にして詳細を教えてください。 – AShシステムカラーをオーバーライドすることもできます。それは私が本当に好きなのは、世界中のものをやりたいときです。トリガーを使用したり、イベントを心配する必要がなくなりました。特定のObjectのSystemColorを設定するだけで、 "MouseOver"が目的の色になります。 [参考](https://blogs.msdn.microsoft.com/wpf/2010/11/30/systemcolors-reference/) –