Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用WPF XAML获得插入阴影_C#_Wpf_Xaml - Fatal编程技术网

C# 如何使用WPF XAML获得插入阴影

C# 如何使用WPF XAML获得插入阴影,c#,wpf,xaml,C#,Wpf,Xaml,我在这里尝试了以下几个不同的答案,以便在我的文本框上实现阴影效果,以下是我迄今为止的代码: <Style x:Key="TextBoxRoundedInset" TargetType="{x:Type TextBox}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <S

我在这里尝试了以下几个不同的答案,以便在我的
文本框上实现阴影效果,以下是我迄今为止的代码:

<Style x:Key="TextBoxRoundedInset" TargetType="{x:Type TextBox}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="TextAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBox}">
                        <Border x:Name="border" CornerRadius="3" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" ClipToBounds="True">
                            <Border Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="-2">
                            <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                            <Border.Effect>
                                    <DropShadowEffect ShadowDepth="0" BlurRadius="10"/>
                                </Border.Effect>
                            </Border>
                        </Border>

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Opacity" TargetName="border" Value="0.56"/>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
                            </Trigger>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
                        <Condition Property="IsSelectionActive" Value="false"/>
                    </MultiTrigger.Conditions>
                    <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
                </MultiTrigger>
            </Style.Triggers>
        </Style>

然后以我拥有的样式显示

<TextBox x:Name="textBox" Background="#263238" Height="40" Margin="0,0,0,50" TextWrapping="Wrap" Width="221" VerticalAlignment="Center" HorizontalAlignment="Center" BorderThickness="0" Style="{DynamicResource TextBoxRoundedInset}" FontSize="25"/>

但我最终得到的结果如下:


我不想让这篇文章有点光彩夺目,相反,我基本上希望文本字段看起来像是被放到背景中的任何关于如何更正的信息都会很好,谢谢

我通常使用
BorderThickness
属性和
BorderBrush
属性结合使用,以提供3D效果,使其看起来像是在内部按下了字段,或者甚至在外部交换两个边框的
边框厚度
的值

这是我用你的剪子做的:

<Border x:Name="border" CornerRadius="3" BorderBrush="White" BorderThickness="0,0,2,2" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" ClipToBounds="True">
    <Border Background="Transparent" BorderBrush="Black" BorderThickness="2,2,0,0" CornerRadius="2">
        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    </Border>
</Border>

缺点是无法再更改
BorderBrush
BorderThickness
属性,因为它们没有绑定


只需根据需要更改这两个边框的颜色,我通常只使用黑色和白色,因为这种组合通常会产生最强烈的效果。

我通常使用
BorderThickness
属性和
BorderBrush
属性结合使用,以产生3D效果,使其看起来好像字段被压在里面一样,或者甚至在外部交换两个边框的
边框厚度
的值

这是我用你的剪子做的:

<Border x:Name="border" CornerRadius="3" BorderBrush="White" BorderThickness="0,0,2,2" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" ClipToBounds="True">
    <Border Background="Transparent" BorderBrush="Black" BorderThickness="2,2,0,0" CornerRadius="2">
        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    </Border>
</Border>

缺点是无法再更改
BorderBrush
BorderThickness
属性,因为它们没有绑定


只需根据需要更改这两个边框的颜色,我通常只使用黑色和白色,因为这种组合通常会产生最强的效果。

老问题,但我的做法有点不同。效果看起来不那么粗糙,这取决于所选的边界笔刷和边界厚度

<Border Background="Transparent"  BorderThickness="2"  BorderBrush="Black">
    <Border.Effect>
        <BlurEffect/>
    </Border.Effect>
    <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>

结果可能看起来像

老问题,但我的做法有点不同。效果看起来不那么粗糙,这取决于所选的边界笔刷和边界厚度

<Border Background="Transparent"  BorderThickness="2"  BorderBrush="Black">
    <Border.Effect>
        <BlurEffect/>
    </Border.Effect>
    <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>

结果可能看起来像

谢谢,除非其他人想出一种不同的黑客方法,否则现在这个方法实际上很有效。知道为什么输入字段中的文本看起来模糊吗,就像它有自己的阴影一样?使用文本元素的对象的阴影效果是当没有背景或填充属性被设置为“透明”时,然后,它还对所述文本元素的内容设置其值。我需要在哪里声明背景透明?您可以通过使用DropShadowEffect拍打a来测试该行为,将background属性保留为空并在其中插入一些文本,然后给它一个背景,例如红色,看看它的区别。谢谢,这实际上是相当好的工作,现在,除非有人想出一个不同的黑客方式来做它。知道为什么输入字段中的文本看起来模糊吗,就像它有自己的阴影一样?使用文本元素的对象的阴影效果是当没有背景或填充属性被设置为“透明”时,然后,它还对所述文本元素的内容设置其值。我需要在哪里声明背景透明?您可以通过使用DropShadowEffect拍打a来测试该行为,将background属性留空并在其中插入一些文本,然后将背景设置为红色,例如,并查看差异。