2009-09-04 2 views
0

이 xaml 텍스트 상자를 C#으로 변환하려고 시도하고 있으므로 코드에서 동적으로 만들고 채울 수 있습니다. 유효성 검사 바인딩을 만드는 데 막혔습니다. 누구든지 힌트를 제공 할 수 있습니까?유효성 검사를 사용하여 XAML 텍스트 상자를 C#으로 변환

<TextBox Height="20" Width="200" > 
     <Binding RelativeSource="{x:Static RelativeSource.Self}" Path="Text" > 
      <Binding.ValidationRules> 
       <runtime:StandardTextBoxValidationRule/> 
      </Binding.ValidationRules> 
     </Binding> 
</TextBox> 
+0

당신은 동적으로 WPF 페이지 내에서 텍스트 상자를 생성하고 있습니까? –

+0

아니요 WPF 페이지와 동일한 어셈블리에있는 컨트롤 생성 클래스에 만들어지지 않습니다. – KithKann

답변

1

당신은 너무처럼 작업을 수행 할 수 있습니다

TextBox textBox = // Get or create the text box 

var binding = new Binding(); 
binding.Source = RelativeSource.Self; 
binding.Path = new PropertyPath("Text"); 
binding.ValidationRules.Add(new StandardTextBoxValidationRule()); 
textBox.SetBinding(TextBox.TextProperty, binding); 
+0

작동하려면 다음을 추가해야했습니다. binding.Path = new PropertyPath ("Text"); 다시 한 번 감사드립니다. – KithKann

+0

다행이었습니다. 다른 사람이 이것을 찾았다면, 내 대답에도 덧붙였다. –

+0

당신은 또한'new Binding ("Text")' –

관련 문제