【问题标题】:WPF Element.Effect, stop affecting child elements?WPF Element.Effect,停止影响子元素?
【发布时间】:2011-03-09 16:18:02
【问题描述】:

我已对该模板的边框应用了一种效果。然后将效果应用于其中的每个元素,因此我得到的阴影比我关心的要多。有没有办法禁用效果?你可以看到我在里面添加了一个模糊效果,但最后我只是得到了模糊的阴影:)

DataTemplate  x:Key="TestInstanceViewModelTemplate">
    <Border BorderThickness="1" BorderBrush="#FF0909B4">
        <Border.Effect>
            <DropShadowEffect/>
        </Border.Effect>
        <DockPanel>
            <DockPanel.Effect>
                <BlurEffect/>
            </DockPanel.Effect>
            <Grid DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="50" Width="1*" />
                    <ColumnDefinition MinWidth="50" Width="1*"/>
                </Grid.ColumnDefinitions>
                <Button Command="{Binding Path=StartCommand}" Content="Start" Grid.Column="0" Grid.Row="0" />
                <Button Command="{Binding Path=StopCommand}" Content="Stop" Grid.Column="1" Grid.Row="0"/>
            </Grid>
            <WpfTestingClient:StatusControl DockPanel.Dock="Top" HorizontalAlignment="Stretch"></WpfTestingClient:StatusControl>
        </DockPanel>
    </Border>
</DataTemplate>

【问题讨论】:

    标签: wpf xaml graphics dropshadow


    【解决方案1】:

    我建议将最上面的容器更改为 Grid 并将您的 Border 和 DockPanel 包含在同一级别,让 Border 位于底部并拉伸以填充 Grid,同时将 DockPanel 放在顶部并添加 1px 边距围绕它来解释你的 BorderThickness。这样一来,投影不仅只适用于 Border 元素,而且您不必在每次内部发生任何变化时都重新渲染效果,从而节省大量资源。

    【讨论】:

    • 狡猾,确实非常狡猾。谢谢。
    猜你喜欢
    • 2021-06-19
    • 2012-08-16
    • 2013-08-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多