पर ध्यान केंद्रित करने वाला टैब मेरे पास TextBox
एक ऑब्जेक्ट की संपत्ति से जुड़ा हुआ है जो IDataErrorInfo
लागू करता है। मैंने TextBox
के Validation.ErrorTemplate
सेट अप किया है, और यह ठीक काम करता है। समस्या यह है कि मेरे पास TabControl
पर है, और यदि मैं टैब को दूसरे में बदलता हूं तो सत्यापन टेम्पलेट और प्रदर्शित नहीं होता है और फिर प्रारंभिक टैब पर वापस आ जाता है (जहां TextBox
है)। ऐसा लगता है कि यह मान्य है (जैसे मान सही है), लेकिन असल में यह नहीं है।WPF सत्यापन (IDataErrorInfo) और टैब
यह IDataErrorInfo
वस्तु है - ध्यान दें कि एक "सही" मान 2 की लंबाई के साथ एक स्ट्रिंग है:
public class Presenter : IDataErrorInfo
{
public Presenter()
{
this.Property = String.Empty;
}
public string Property { get; set; }
public string Error { get { return null; } }
public string this[string columnName]
{
get
{
if (columnName == "Property")
{
if (this.Property.Length == 2)
return null;
else
return "Invalid property length!";
}
else return null;
}
}
}
और इस XAML है:
<TabControl >
<TabItem Header="tabItem1" Name="tabItem1" GotFocus="tabItem1_GotFocus">
<Grid>
<TextBox Width="100" Height="20" x:Name="txtField">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="16"/>
</Grid.ColumnDefinitions>
<AdornedElementPlaceholder Grid.Column="0"/>
<Image Source="bullets16.png" Grid.Column="1" ToolTip="{Binding CurrentItem.ErrorContent, Mode=OneWay}">
</Image>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TextBox.Style>
<TextBox.Text>
<Binding Path="Property" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True">
</Binding>
</TextBox.Text>
</TextBox>
</Grid>
</TabItem>
<TabItem Header="tabItem2" Name="tabItem2" >
<Grid />
</TabItem>
</TabControl>
क्या पर कोई भी विचार मैं गलत कर रहा हूँ?
यह भी 'Expander' की सामग्री के साथ एक समस्या है, और एक ही समाधान लागू होता है। –
एक संबंधित ब्लॉग पोस्ट - [TabItems स्विच करते समय WPC Validation त्रुटियां TabControl के अंदर गायब हो जाती हैं] (http://karlshifflett.wordpress.com/2008/02/19/wpf-validation-errors-disappear-inside-tabcontrol-when-switching- tabitems /) – akjoshi
एक पूरा समाधान नहीं है। आरंभिक सत्यापन केवल पहले चयनित टैब आइटम के लिए काम करता है, जब आप बाद में स्विच करते हैं तो उनमें से बाकी स्वचालित रूप से मान्य नहीं होंगे। मुझे पता चला कि ऑनलोड पर कोड में डेटाकॉन्टेक्स्ट मैन्युअल रूप से सेट करके मैन्युअल रूप से इस समस्या को हल करता है लेकिन यह बदसूरत है। मैं अभी भी एक समाधान की तलाश कर रहा हूं ... – MoonStom