2013-06-26 9 views
3

이것을 예로 들어 보겠습니다. 이제 총 8 개의 텍스트 상자가 있습니다. 정적 리소스 스타일을 사용하여 모두 동일한 스타일링 세트를 사용하는지 확인합니다. 그러나 텍스트 상자 중 일부가 아래쪽 경계선을 갖고 다른 일부가 그렇지 않은 것을주의하십시오. 왜 이런 일이 생길까요?테두리 너비가 일정하지 않게 표시됩니다.

enter image description here 다음은 위의 모든 의견 제안으로 레이아웃이없는 문제가 매우 비효율적 비록 코드를

<Style x:Key="AddressTextBox" TargetType="TextBox">    
     <Setter Property="MinWidth" Value="230"></Setter> 
     <Setter Property="MaxWidth" Value="260"></Setter> 
     <Setter Property="MaxLength" Value="45"></Setter> 
     <Setter Property="Margin" Value="1"></Setter> 
     <Setter Property="BorderThickness" Value="1,1,1,1"/> 
     <Setter Property="HorizontalAlignment" Value="Left"/> 
     <Setter Property="Padding" Value="1,2,0,1"/> 
     <Setter Property="BorderBrush" Value="Gray"></Setter> 
     <Setter Property="Height" Value="20"></Setter> 
    </Style> 

<DockPanel> 
    <StackPanel> 
     <Grid Margin="5"> 
      <StackPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7">Postal</TextBlock> 
         <TextBox Style="{StaticResource AddressTextBox}"></TextBox>            
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="10"></DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7">Street</TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
       <DockPanel Height="Auto"> 
        <TextBlock Width="50" Margin="7"></TextBlock> 
        <TextBox Style="{StaticResource AddressTextBox}"></TextBox> 
       </DockPanel> 
      </StackPanel> 
     </Grid> 
    </StackPanel> 
</DockPanel> 
+0

의 경계선 = "0,0,0,2"의 첫 번째 PaymentTerms 텍스트 상자, 경계선의되지만 경계선의 = "0,0,0,1"온 : 비 효율성을 최소화하기 위해, 나는 Grid을 사용 다른 것들? – SvenG

+1

안녕하세요 SvenG - 죄송합니다. 오타가 있습니다. 문제를 해결 한 후에도 문제가 여전히 존재합니다. –

+0

주변 Panel이란 무엇입니까? StackPanel''으로 빈 폼에 코드를 복사하거나 붙여 넣었습니다. 괜찮습니다. – SvenG

답변

1

을합니다. SnapToDevicePixels, Padding, Margins 등과 아무 관련이 없습니다. TextBox' 제어 스타일의 일부입니다. BorderWidth을 기본값보다 크게 설정하면 모든 구석에 달라 붙지 만 그 아래로 가면 그렇지 않습니다. TextBox의 템플릿을 추출하면 테두리와 스타일을 볼 수 있습니다. 그래서이 불규칙성을 "이기기"위해서, 스타일에서 의 Border 속성을 간접적으로 조작하려고하는 대신 템플릿을 덮어 써야합니다. 그런 다음 Border을 직접 Template에 직접 입력하십시오. 또한

<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="LightGray"/> 
    <SolidColorBrush x:Key="DisabledForegroundBrush" Color="Gray"/> 
    <SolidColorBrush x:Key="EnabledBackgroundBrush" Color="White"/> 

    <Style x:Key="AddressTextBox" TargetType="{x:Type TextBoxBase}"> 
     <Setter Property="SnapsToDevicePixels" Value="True"/> 
     <Setter Property="OverridesDefaultStyle" Value="True"/> 
     <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/> 
     <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
     <Setter Property="AllowDrop" Value="true"/> 
     <Setter Property="MinWidth" Value="230"/> 
     <Setter Property="MaxWidth" Value="260"/> 
     <Setter Property="Margin" Value="1"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="HorizontalAlignment" Value="Left"/> 
     <Setter Property="Padding" Value="1,2,0,1"/> 
     <Setter Property="Height" Value="20"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TextBoxBase}"> 
        <Border Name="Border" CornerRadius="2" Padding="2" Background="{StaticResource EnabledBackgroundBrush}" 
          BorderBrush="Gray" BorderThickness="1" > 
         <ScrollViewer Margin="0" x:Name="PART_ContentHost"/> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsEnabled" Value="False"> 
          <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> 
          <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/> 
          <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

, 레이아웃에 대한 단지 팁 :

여기에 (내가 그것으로 당신의 세터에 연결) 작업을하는 스타일이다.

<Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition/> 
      <ColumnDefinition/> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition/> 
      <RowDefinition/> 
      <RowDefinition/> 
      <RowDefinition/> 
      <RowDefinition/> 
      <RowDefinition/> 
      <RowDefinition/> 
     </Grid.RowDefinitions> 

     <TextBlock Text="Postal"/> 
     <TextBox Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="1" /> 
     <TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="2" /> 
     <TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="3" /> 
     <TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="4" Text="Street" Margin="7,10,7,7"/> 
     <TextBox Grid.Row="4" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="5"/> 
     <TextBox Grid.Row="5" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="6"/> 
     <TextBox Grid.Row="6" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 

     <TextBlock Grid.Row="7"/> 
     <TextBox Grid.Row="7" Grid.Column="1" Style="{StaticResource AddressTextBox}"/> 
    </Grid> 
관련 문제