Wpf StaticResource更改文本框的边框

Wpf StaticResource更改文本框的边框,wpf,xaml,Wpf,Xaml,我需要文本框的占位符,并找到以下工作代码: <Style x:Key="placeHolder" TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}">

我需要文本框的占位符,并找到以下工作代码:

<Style x:Key="placeHolder" TargetType="{x:Type TextBox}">   
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid>
                        <TextBox Text="{Binding Path=Text,
                                            RelativeSource={RelativeSource TemplatedParent}, 
                                            Mode=TwoWay,
                                            UpdateSourceTrigger=PropertyChanged}"
                             x:Name="textSource" 
                             Background="Transparent" 
                             Panel.ZIndex="2" 
                                 BorderThickness="0,0,0,1"/>
                        <TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
                            <TextBox.Style>
                                <Style TargetType="{x:Type TextBox}">
                                    <Setter Property="Foreground" Value="Transparent"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
                                            <Setter Property="Foreground" Value="LightGray"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>
                        </TextBox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

这是我的文本框:

<TextBox x:Name="isci_tb" HorizontalAlignment="Left" Height="25" Margin="0,0,0,0" TextWrapping="Wrap"
          VerticalAlignment="Center" Width="120" BorderThickness="0, 0, 0, 1" TextChanged="isci_tb_TextChanged" Tag="išči" Style="{StaticResource placeHolder}">
            <TextBox.Background>
                <ImageBrush/>
            </TextBox.Background>
        </TextBox>


因为我是XAML新手,所以我看不到按钮的边框在哪里或什么地方发生了变化。我希望只显示底部边框,但会显示所有4个边框。

将模板中内部文本框的BorderThickness属性设置为0:

<Style x:Key="placeHolder" TargetType="{x:Type TextBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBox}">
                <Grid>
                    <TextBox Text="{Binding Path=Text,
                                            RelativeSource={RelativeSource TemplatedParent}, 
                                            Mode=TwoWay,
                                            UpdateSourceTrigger=PropertyChanged}"
                             x:Name="textSource" 
                             Background="Transparent" 
                             Panel.ZIndex="2" 
                                 BorderThickness="0,0,0,1"/>
                    <TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1"
                                     BorderThickness="0">
                        <TextBox.Style>
                            <Style TargetType="{x:Type TextBox}">
                                <Setter Property="Foreground" Value="Transparent"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
                                        <Setter Property="Foreground" Value="LightGray"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                    </TextBox>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


成功了,谢谢!我可以问一下为什么在这里,为什么在这个模板中有两个不同的文本框吗?我正在寻找一个关于高级XAML(绑定,控制模板…)的指南,但还没有找到任何东西。我不知道。这是你的模板:)一般来说,你不会把文本框放在文本框的控件模板中,但我猜你是从某个地方得到这种风格的。就像我说的,我在Stackoverflow上找到了它,它正在工作,是的。我会试着在XAML上找到一些指南,因为我会非常需要它,呵呵。