2017-05-23 13 views
0

同じ質問シナリオを検索しましたが、不明瞭で、ボタンのほとんどがユーザーコントロールではありません。ユーザーコントロールでマウスオーバーオーバーエフェクト効果を無効にする方法

 private void Button_Click(object sender, RoutedEventArgs e) 
    {   
     ContentArea.Content = new Views.DashboardView(); 
    } 

が、そのユーザーコントロールがロードされたとき、私は私のマウスでそれにカーソルを合わせると、ウィンドウ全体がハイライト表示、個々のではなく、強調表示されています:

は、私は私がメインウィンドウからこの方法を読み込むユーザーコントロールを持っていますそのウィンドウ内のコントロール

user control highlighted

は黒い輪郭線に囲まれたコントロールは、イベントの上にマウスの上に完全にハイライト表示され、ユーザーコントロールです。この強調表示エフェクトを無効にして、コントロール全体をハイライト表示しなくても、ユーザーコントロール内の「管理」ボタンなどを強調表示する方法はありますか?ここで

は私のユーザーコントロールのXAMLコードです:

<UserControl x:Class="S.O.B_Management_System.Views.DashboardView" 
      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:local="clr-namespace:S.O.B_Management_System.Views" 
      mc:Ignorable="d"    
      d:DesignHeight="300" d:DesignWidth="540"> 

    <Grid> 
     <ListView> 
      <ScrollViewer Height="300"> 
       <StackPanel> 
        <StackPanel Orientation="Horizontal"> 
         <TextBlock Background="LightBlue" Width="150" Height="90" Margin="10"> 
         <StackPanel Orientation="Vertical"> 
         <TextBlock Margin="10" Width="130" Background="White" Text="TRIANGLES" Padding="35,3,5,3" FontFamily="Century Gothic"/> 
         <Button Content="Manage" Width="100" Margin="0,15,0,0" Click="Button_Click"/> 
          </StackPanel> 
        </TextBlock> 
         <TextBlock Background="LightBlue" Width="150" Height="90" Margin="10"> 
         </TextBlock> 
         <TextBlock Background="LightBlue" Width="150" Height="90" Margin="10"> 
         </TextBlock> 
        </StackPanel> 
       </StackPanel> 
      </ScrollViewer> 
     </ListView> 
    </Grid> 
</UserControl> 

と私のメインウィンドウのXAMLコード:

<Window x:Class="S.O.B_Management_System.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:S.O.B_Management_System" 
     xmlns:vm="clr-namespace:S.O.B_Management_System.Views" 
     mc:Ignorable="d" 
     WindowStartupLocation="CenterScreen" 
     Title="MainWindow" Height="700" Width="1250"> 
    <Window.Resources> 
     <DataTemplate DataType="{x:Type vm:DashboardView}"> 
      <vm:DashboardView /> 
      <!-- This is a UserControl --> 
     </DataTemplate> 

    </Window.Resources> 
    <DockPanel> 
     <Menu DockPanel.Dock="Top"> 
      <MenuItem Header="Test"> 
      </MenuItem> 
     </Menu> 
     <StackPanel Orientation="Horizontal"> 
      <DockPanel> 

       <StackPanel Width="230" Orientation="Vertical" DockPanel.Dock="Left"> 
        <ListView Height="400"> 
         <ListViewItem Name="dash" Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"> 

         </ListViewItem> 
         <ListViewItem Content="Inventory" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
         <ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
         <ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
         <ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
         <Button Height="20" Width="60" Content="{Binding Name}" 
          Command="{Binding DataContext.ChangePageCommand, 
          RelativeSource={RelativeSource AncestorType={x:Type Window}}}" 
          CommandParameter="{Binding}" 
          Margin="2,5" Click="Button_Click"/> 
        </ListView> 
       </StackPanel> 
       <StackPanel Orientation="Vertical" DockPanel.Dock="Right"> 

        <ContentControl x:Name="ContentArea" /> 
       </StackPanel> 
      </DockPanel>  
     </StackPanel> 
    </DockPanel> 
</Window> 

すべてのヘルプは喜ん

+0

ありがとうございました。これがちょっとだけのような気がするなら、私たちのマウスがユーザコントロールエリアに入るたびにスタイルを持つトリガを作成してください。 – Bojje

+0

私はスタックパネルをテキストブロック内に入れ子にすることをお勧めしませんが、それは別の話です...この質問には表示されていないことが間違いありません。マウスオーバーエフェクトは、ここに示すXAMLでは定義されていません。 – grek40

+0

Bojjeあなたの解決策は答えです。残念なことに15名の評判が悪いので、私はあなたのコメントをアップヴォートしません –

答えて

0

をいただければ幸いあなたは含みスタイルのトリガーを定義する必要がありますあなたが興味を持っている部分のIsMouseOver。例えば、マウスが上にあるときに選択したリストボックス項目の色を変更するには、これを行うことができます

<ListBox> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
        <Setter Property="Background" Value="Blue"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

リソースディクショナリを使用していない場合は、ユーザーコントロール自体でスタイルを定義する方が簡単です。あなたはポップアップ内にネストされたリストボックスを持っているし、あなたがこの

<UserControl> 
    <Grid> 
     <TextBox> 
     <Popup> 
      <ListBox> 
       <ListBox.ItemContainerStyle> 
        <Style TargetType="ListBoxItem"> 
         <Style.Triggers> 
          <Trigger Property="IsMouseOver" Value="True"> 
           <Setter Property="Background" Value="Blue"/> 
          </Trigger> 
         </Style.Triggers> 
        </Style> 
       </ListBox.ItemContainerStyle> 
      </ListBox> 
     </Popup> 
    </Grid> 
</UserControl> 
+0

これはおそらくマウスオーバーでスタイルを有効にする方法の質問の解決策になるでしょう。しかし、問題はいくつかのマウスオーバー効果を無効にする*方法です。だから私は効果が現在どのように実装されているかを見るまで、答えがあるのではないかと疑う。 – grek40

+0

私は約6ヶ月前に同様の問題がありました。私はポップアップでリストボックスを持っていて、マウスの上に選択した項目を強調表示したかった。私はIsMouseOverトリガーをusercontrolではなくlistboxitemに配置することがわかった。 この場合、マウスで管理ボタンを強調表示するには、ユーザーコントロールではなくボタンにIsMouseOverトリガーを配置する必要があります。 – Gareth

+0

あなたのソリューションは動作しますが、この場合、問題はスタックパネルのどこかにあります。私はスタックパネルを削除し、私のリストビューをドッキングし、問題はなくなった。スタックパネルを絡み合わせてソリューションを使用することで、引き続き問題が発生します。ありがとうございました –

0

を行うことができ、選択した項目の色を変更したい場合たとえば、私は私のDashboardView

に絡み合っスタックパネルを削除することで問題を解決しました
<UserControl x:Class="S.O.B_Management_System.Views.DashboardView" 
    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:local="clr-namespace:S.O.B_Management_System.Views" 
    mc:Ignorable="d"    
    d:DesignHeight="300" d:DesignWidth="540"> 
<Grid> 
<DockPanel>  

<ListView Height="400" DockPanel.Dock = Top> 
<ListViewItem Name="dash" Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"> 
</ListViewItem> 
<ListViewItem Content="Inventory" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
<ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
<ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
<ListViewItem Content="Dashboard" FontFamily="Century Gothic" FontWeight="Bold" Height="30" Background="AliceBlue"/> 
<Button Height="20" Width="60" Content="{Binding Name}"Command="{Binding DataContext.ChangePageCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" CommandParameter="{Binding}" Margin="2,5" Button_Click"/> 
</ListView> 

</DockPanel> 
</Grid> 
</UserControl> 

は、私はよく分からないが、私はあなたのstackpanelsやdockpanelsのいずれかのいくつかは、この中に泥棒することができると思うあなたの助け

関連する問題