【问题标题】:WPF borderless form using WindowGlows to create a dropshadowWPF 无边框窗体使用 WindowGlows 创建阴影
【发布时间】:2014-12-23 02:25:11
【问题描述】:

所以我在寻找让无边框 wpf 表单投下阴影的方法时找到了this。它会创建类似于 Visual Studio 或 Microsoft Office 的阴影。从上述站点下载后,我在我的项目中引用了 WindowGlows.dll 文件,并从视线示例中复制了此代码。

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WindowGlows="http://GlowWindow.codeplex.com/"
    x:Class="WindowGlowsTestApp.MainWindow"
    Title="MainWindow"
    Height="350"
    Width="525"
    WindowGlows:GlowManager.EnableGlow="True"
    WindowGlows:GlowManager.ActiveGlowBrush="CornflowerBlue"
    WindowGlows:GlowManager.InactiveGlowBrush="LightGray">
<WindowChrome.WindowChrome>
    <WindowChrome GlassFrameThickness="0"
                  CornerRadius="0"
                  CaptionHeight="36"
                  ResizeBorderThickness="0" />
</WindowChrome.WindowChrome>
<Border BorderThickness="1"
        BorderBrush="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="36" />
            <RowDefinition />
            <RowDefinition Height="24" />
        </Grid.RowDefinitions>
        <Rectangle Fill="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
                   Margin="-1,11,-1,0"
                   StrokeThickness="0"
                   ClipToBounds="True" />
        <TextBlock HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   Text="{Binding Title, RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}"
                   Foreground="{Binding Path=(WindowGlows:GlowManager.InactiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
                   Margin="0,11,0,0" />
        <Rectangle Grid.Row="2"
                   Fill="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
                   Margin="-1,0,-1,-1"
                   StrokeThickness="0"
                   ClipToBounds="True" />
    </Grid>
</Border>

当我点击开始时,表单会出现一个梦幻般的阴影,我可以充分利用它,但我无法摆脱错误,这告诉我

Error   1   The name "GlowManager" does not exist in the namespace

我又收到 6 个关于发光管理器的错误,但没有其他错误,如何更正命名空间?

【问题讨论】:

  • 您的实际问题是什么?
  • 为什么命名空间无效,直到我解决了 xmal 是无效标记并且我无法在设计视图中工作的错误,我已经尝试访问 this page 并尝试了一些来自有但无济于事。

标签: wpf winforms xaml window dropshadow


【解决方案1】:

在阅读this link 之后,我将整个项目直接复制到我的 C 驱动器的根目录中并从那里打开它,现在它工作得非常好。看起来这是一个视觉工作室的错误。

【讨论】:

    【解决方案2】:

    我觉得那个命名空间不合适。

    假设您在项目中使用了对娃娃的引用,获得这些权利的最简单方法是使用混合,从资产选项卡中拖放该 DSL 中的对象,然后它会完成剩下的工作。 visual studio 的帮助有点小。

    在没有看到你所拥有的东西的情况下,我能提供的最好的方法是将命名空间标签更改为这种形式的东西......

    Xmlns:windowchrome="clr-namespace:<namespace of targeted objects>,assembly=<assembly name as seen in references folder>"
    

    msdn 包含更多详细信息,http://msdn.microsoft.com/en-gb/library/bb514546%28v=vs.90%29.aspx

    【讨论】:

    • 我尝试了这种声明命名空间的方式,但没有成功,不过,混合技巧会派上用场......
    • 刚刚注意到我在那个命名空间元素中有一个空格。为清晰起见将进行编辑,但很高兴混合提示至少有所帮助。
    猜你喜欢
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 2018-08-29
    • 2012-02-15
    • 1970-01-01
    相关资源
    最近更新 更多