0

i am a beginner in wpf and trying to understand the solution in the below Url, as i have to create a condition in Event Trigger.

How to give the condition for EventTrigger?

Can anyone please explain the line my:ConditionalEventTrigger.Triggers. I am trying to understand where did the triggers came from. Is it from the attached property, if that is the case i tried creating my own attached properties but was not able to see them.

public static ConditionalEventTriggerCollection GetTriggers(DependencyObject obj) { return (ConditionalEventTriggerCollection)obj.GetValue(OwnProperty); }
    public static void SetTriggers2(DependencyObject obj, ConditionalEventTriggerCollection2 value) { obj.SetValue(OwnProperty, value); }
    public static readonly DependencyProperty OwnProperty = DependencyProperty.RegisterAttached("Own", typeof(ConditionalEventTriggerCollection2), typeof(TestingCustomTriggers), new PropertyMetadata
    {
        PropertyChangedCallback = (obj, e) =>
        {
            // When "Triggers" is set, register handlers for each trigger in the list 
            var element = (FrameworkElement)obj;
            var triggers = (List<TestingCustomTriggers>)e.NewValue;
            foreach (var trigger in triggers)
                element.AddHandler(trigger.RoutdEvent, new RoutedEventHandler((obj2, e2) =>
                  trigger.OnRoutedEvent(element)));
        }
    });

I created my own attached property like above but for some reason, I was not able to see it. I really appreciate your time in looking into this.

thanks

Community
  • 1
  • 1
5413
  • 80
  • 6
  • yes it is AP and in ray's answer it is explained, http://stackoverflow.com/a/3409705/3026795 Can you post your codes? so we can check ? – WPFUser Dec 21 '16 at 06:14
  • Updated my question showing how i created my AP, but for some reason i don't see this in XAML. Can anyone explain why. – 5413 Dec 22 '16 at 00:42
  • Hi WPFUser, Can you please answer for above. – 5413 Dec 27 '16 at 21:05
  • can you let us know , why there is no set,get for "Own" Property ? and what is "SetTriggers2("? – WPFUser Dec 28 '16 at 05:30
  • 1
    https://msdn.microsoft.com/en-us/library/ms749011(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3 see this syntax.. also typing "propa" and pressing double tab will write Attached Property with property syntax in VS – WPFUser Dec 28 '16 at 05:32
  • i have updated my question now, you can see set, get for the property. Always nice to learn shortcut , thanks – 5413 Dec 28 '16 at 16:47
  • thanks WPFUser, when i created Attached Property using the shortcut "propa". I was able to see the attached Property in the XAML. Thanks once again for your help. – 5413 Dec 28 '16 at 17:02

0 Answers0