我已经搜索了相同的问题场景,但它们不清楚,并且大多数关注按钮而不是用户控件。
我有一个用户控件,我通过这种方式从主窗口加载:
private void Button_Click(object sender, RoutedEventArgs e)
{
ContentArea.Content = new Views.DashboardView();
}
但是当加载该用户控件时,当我用鼠标悬停在它上面时,整个窗口都会突出显示,而不是突出显示该窗口中的各个控件
被黑色轮廓包围的控件是在鼠标悬停事件上完全突出显示的用户控件。有没有办法禁用这种突出显示效果,只需突出显示用户控件中的“管理”按钮,而不突出显示整个控件。
这是我的用户控件 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>
任何帮助将不胜感激
我通过删除 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 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>
谢谢大家的帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句