2014-01-19 38 views
0

所以我設置一個文本框和標籤:如何使文本框和標籤的大小相同?

 <TextBox Height="23" HorizontalAlignment="Right" Margin="0,74,119,0" Name="txb_idleTime" VerticalAlignment="Top" Width="162"> 
      <Validation.ErrorTemplate> 
       <ControlTemplate> 
        <StackPanel> 
         <!-- Placeholder for the TextBox itself --> 
         <AdornedElementPlaceholder x:Name="textBox"/> 
         <TextBlock Text="{Binding [0].ErrorContent}" Foreground="Red"/> 
        </StackPanel> 
       </ControlTemplate> 
      </Validation.ErrorTemplate> 
      <TextBox.Text> 
       <Binding Path="MinIdleTime" UpdateSourceTrigger="PropertyChanged" > 
        <Binding.ValidationRules> 
         <Local:NumberValidation /> 
        </Binding.ValidationRules> 
       </Binding> 
      </TextBox.Text> 
     </TextBox> 
     <Label Content="Minimum Idle Time (min):" Height="28" HorizontalAlignment="Left" Margin="65,72,0,0" Name="label1" VerticalAlignment="Top" Width="160" HorizontalContentAlignment="Right" Target="{Binding}" /> 

目前直屬文本框這樣的錯誤信息顯示:

enter image description here

我想它看起來是這樣的:

enter image description here

我該怎麼做?

回答

1

指定負的左邊距至錯誤文本塊等於標籤的寬度。這應該工作:

<TextBlock Text="{Binding [0].ErrorContent}" Margin="-160,0,0,0" 
      Foreground="Red"/> 
0

我可能會用這種方法:MSDN Validation。我還沒有使用它,但聽起來好像它適合您的需求。

相關問題