Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF - Styles with Custom Properties
    primarykey
    data
    text
    <p>I'm developing a document number checking on my application and I wrote an attached behavior to textbox to check the text. Here's the behavior code:</p> <pre><code> public class CPFTextBehavior : Behavior&lt;TextBox&gt; { static readonly DependencyPropertyKey IsCPFPropertyKey = DependencyProperty.RegisterAttachedReadOnly("IsCPF", typeof(bool), typeof(CPFTextBehavior), new FrameworkPropertyMetadata(false)); public static readonly DependencyProperty IsCPFProperty = IsCPFPropertyKey.DependencyProperty; public static bool GetIsCPF(TextBox tb) { return (bool)tb.GetValue(IsCPFProperty); } public bool IsCPF { get { return GetIsCPF(AssociatedObject); } private set { AssociatedObject.SetValue(IsCPFPropertyKey, value); } } protected override void OnAttached() { base.OnAttached(); AssociatedObject.TextChanged += LocusProject.Validacao.CPF_CNPJValidation.ValidateCPF; AssociatedObject.PreviewTextInput += LocusProject.Validacao.CPF_CNPJValidation.ValidateCPFMask; DataObject.AddPastingHandler(AssociatedObject, LocusProject.Validacao.CPF_CNPJValidation.PastingCPFMask); AssociatedObject.PreviewKeyDown += Interactivity.PreventInsertKey; } protected override void OnDetaching() { base.OnDetaching(); AssociatedObject.TextChanged -= LocusProject.Validacao.CPF_CNPJValidation.ValidateCPF; AssociatedObject.PreviewTextInput -= LocusProject.Validacao.CPF_CNPJValidation.ValidateCPFMask; DataObject.RemovePastingHandler(AssociatedObject, LocusProject.Validacao.CPF_CNPJValidation.PastingCPFMask); AssociatedObject.PreviewKeyDown -= Interactivity.PreventInsertKey; } } </code></pre> <p>And here's what i'm doing on my ResourceDictionary:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="clr-namespace:LocusProject"&gt; &lt;Style TargetType="{x:Type TextBox}" x:Key="TextFields"&gt; &lt;Setter Property="BorderBrush" Value="DarkBlue"/&gt; &lt;Setter Property="BorderThickness" Value="1"/&gt; &lt;Style.Triggers&gt; &lt;EventTrigger RoutedEvent="TextBox.GotFocus"&gt; &lt;EventTrigger.Actions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.0000000" Value="White"/&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.3500000" Value="LightBlue"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger.Actions&gt; &lt;/EventTrigger&gt; &lt;EventTrigger RoutedEvent="TextBox.LostFocus"&gt; &lt;EventTrigger.Actions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.0000000" Value="LightBlue"/&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.3500000" Value="White"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger.Actions&gt; &lt;/EventTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type TextBox}" x:Key="CPFField" BasedOn="{StaticResource TextFields}"&gt; &lt;Setter Property="i:CPFTextBehavior.IsCPF" Value="True" /&gt; &lt;/Style&gt; </code></pre> <p></p> <p>But here's the thing. It says "Exception has been thrown by the target of invocation." and I can't get it to work.</p> <p>Am I doing something wrong? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload