2017-08-02 99 views
0

我在文本框周圍有一個圓角邊框。顯示時,儘管將「BorderThickness」屬性設置爲0並將「BorderBrush」設置爲透明,但文本框的水平頂部和底部行仍顯示出來。我怎樣才能做文本框的邊框不顯示?WPF邊框和文本框問題.NET 3.5

代碼如下:

<Border Grid.Row="0" Grid.Column="0" 
     BorderBrush="DarkBlue"   
     BorderThickness="0.8" 
     CornerRadius="5" 
     Margin="5,10,3,10" 
     Height="Auto" Width="Auto" 
     Background="AliceBlue" 
     HorizontalAlignment="Left"> 

     <TextBox x:Name="txtSearch" 
       Width="250" 
       Style="{StaticResource WatermarkedTextBox}" 
       VerticalAlignment="Center" 
       HorizontalAlignment="Left" 
       BorderBrush="Transparent" 
       BorderThickness="0" 
       Margin="1"/> 
</Border> 

任何想法,爲什麼正在顯示的文本框的邊界?

未遂#1

我發現,罪魁禍首是附加的風格,即靜態資源WatermarkedTextBox這是如下:

<Style x:Key="WatermarkedTextBox" TargetType="TextBox"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="TextBox"> 
       <Grid> 
        <TextBox Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" /> 
        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" 
          Text="{TemplateBinding Tag}" 
          Margin="5,0,5,0" 
          Foreground="#FF808080" 
          FontStyle="Italic" 
          IsHitTestVisible="False" 
          x:Name="UserMessage" 
          Visibility="Hidden"/> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="Text" Value=""/> 
          <Condition Property="IsKeyboardFocusWithin" Value="False"/> 
         </MultiTrigger.Conditions> 
         <Setter Property="Visibility" TargetName="UserMessage" Value="Visible"/> 
        </MultiTrigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

所以,我怎麼能解決這個問題?

+0

有人知道爲什麼它是怎麼回事?任何幫助將不勝感激。謝謝。 – user1624552

回答

0

的罪魁禍首是在風格「WatermarkedTextbox」,所以設置了borderThickness屬性設置爲0設置文本框的邊框是現在工作:

<Style x:Key="WatermarkedTextBox" TargetType="TextBox"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="TextBox"> 
       <Grid> 
        <TextBox BorderThickness="0" 
          Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" /> 
        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" 
          Text="{TemplateBinding Tag}" 
          Margin="5,0,5,0" 
          Foreground="#FF808080" 
          FontStyle="Italic" 
          IsHitTestVisible="False" 
          x:Name="UserMessage" 
          Visibility="Hidden"/> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <MultiTrigger> 
         <MultiTrigger.Conditions> 
          <Condition Property="Text" Value=""/> 
          <Condition Property="IsKeyboardFocusWithin" Value="False"/> 
         </MultiTrigger.Conditions> 
         <Setter Property="Visibility" TargetName="UserMessage" Value="Visible"/> 
        </MultiTrigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style>