1

当用户悬停“mybutton”时,我试图让窗口框架出现。这应该有效,但由于某种原因它不是。我错过了什么?

<Window x:Class="test2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" WindowStyle="None"  Loaded="ShellWindow_SourceInitialized"   x:Name="mywindow">
<Window.Resources>
    <Style TargetType="{x:Type Window}">            
        <Style.Triggers>            
            <DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=mybutton}" Value="True">
                <Setter Property="ResizeMode" Value="CanResize" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=mybutton}" Value="False">
                <Setter Property="ResizeMode" Value="NoResize" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

</Window.Resources>
<Grid Name="mygrid" Loaded="Grid_Loaded">
    <Button Name="mybutton" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="75"/>
</Grid>

(如果您想知道那些“已加载”功能是什么,它们会在保留阴影的同时删除 chrome 并允许透明度 = false http://marcin.floryan.pl/blog/2010/08/wpf-drop-shadow-with-windows -dwm-api)最后它不会是按钮,而是会在整个窗口边框上做出反应(我找不到更好的方法来启用调整大小,同时删除所有 chrome)

4

2 回答 2

2

在风格 TargetType 应该是 MainWindow

<Style TargetType="{x:Type local:MainWindow}">
其中 local 必须映射到您的命名空间:

xmlns:local="clr-namespace:test2"
于 2013-09-18T20:22:49.970 回答
1

myButton 是在 style 之后定义的。XAML 解析器并不那么聪明。使用以下 XAML 来获得您的预期行为:

<Window x:Class="test2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" WindowStyle="None"  Loaded="ShellWindow_SourceInitialized"   x:Name="mywindow">

    <Grid Name="mygrid" Loaded="Grid_Loaded" >
        <Button Name="mybutton" Content="Button" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="75"/>
    </Grid>
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=mybutton}" Value="True">
                    <Setter Property="ResizeMode" Value="CanResize" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=mybutton}" Value="False">
                    <Setter Property="ResizeMode" Value="NoResize" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

    </Window.Style>
</Window>
于 2013-09-18T20:22:58.307 回答