2012-05-18 2 views
0

여기 내 TextBox 텍스트가 contentemplate의 자식 텍스트 상자에 바인딩되지만 기본 스타일 및 유효성 검사 오류와 함께 콘텐츠 템플릿의 자식 텍스트 상자에 적용하는 방법입니다.Silverlight의 콘텐츠 템플릿에서 하위 컨트롤에 부모 컨트롤의 스타일

<TextBox x:Name="tbIdNumber" Width="110" Height="20" Text="{Binding IdNumber, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" > 
     <TextBox.Template> 
      <ControlTemplate TargetType="TextBox" >      
       <StackPanel Orientation="Horizontal" > 
        <Image Height="10" Width="20" Source="Images/bullet_darkblue.PNG" /> 
        <TextBox Width="90" Tag="{Binding RelativeSource={RelativeSource TemplatedParent}}" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent},Path=DataContext, Mode=TwoWay}" 
           Text="{Binding Path=Text ,RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" >       
        </TextBox> 
       </StackPanel> 
      </ControlTemplate> 
     </TextBox.Template> 
    </TextBox> 

답변

0

TextBox를 사용하여 TextBox 컨트롤의 컨트롤 템플릿을 정의하는 것은 매우 드문 경우입니다. 위 경로를 따르지 않는 것이 좋습니다.

TextBox의 기본 ControlTemplate으로 시작해야합니다 (here) (경고 : 매우 복잡합니다). 여기에는 유효성 검사, 초점을 맞추기 위해 필요한 모든 시각적 상태가 포함되어 있습니다.

내가 관찰 한 바로는 텍스트 상자 옆에 이미지를 추가하려고합니다. 그리드 안에 이미지 요소를 추가 한 다음 테두리에서 여백을 조정할 수 있어야합니다. 스 니펫은 다음과 같습니다.

<Image Height="10" Width="20" Source="Images/bullet_darkblue.PNG" /> 
<Border Margin="20,10,0,0" 
     x:Name="MouseOverBorder" BorderThickness="1" BorderBrush="Transparent"> 
    <ScrollViewer x:Name="ContentElement" Padding="{TemplateBinding Padding}" 
    BorderThickness="0" IsTabStop="False"/> 
</Border> 
관련 문제