Hi
I'm currently working on some extended Forms controls. I use bindable properties, but somehow the "OnElementPropertyChanged" wont get triggered with my "custom" properties. I just cant seem to figure out if I'm doing anything wrong or ?
I have this forms class called "FormEntry". When using it from code, I create it like this :
FormEntry fe = new FormEntry () { Triggers = { new EventTrigger () { Event = "MyEvent", Actions = { new EntryValidation () } } } };
The code for the for the trigger action class getting called is this :
public class EntryValidation : TriggerAction<FormEntry> { protected override void Invoke (FormEntry sender) { Debug.WriteLine ("3 - EntryValidation called"); if (sender.Text.Length > 5) { sender.Validated = true; } else { sender.Validated = false; } } }
In my FormEntry class code, I have the "Validated" property defined as follows :
public static readonly BindableProperty ValidatedProperty = BindableProperty.Create("Validated", typeof(bool), typeof(FormEntry), false, BindingMode.TwoWay); public bool Validated { get { return (bool)base.GetValue(FormEntry.ValidatedProperty); } set { Debug.WriteLine ("4 - FormEntry : Validated setter called!"); base.SetValue(FormEntry.ValidatedProperty, value); } }
When I run the code, I can debug and the above setter IS called as a result from setting the value in the "trigger action class", but unfortunately the "OnElementPropertyChanged" in the renderer class is NOT getting triggered:
protected override void OnElementPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged (sender, e); Console.WriteLine ("OnElementPropertyChanged called"); SetProperties (sender); }
Am I missing something here? I've read that the notification should be implemented automatically, when i define my bindings as I do.
If someone please could help me figure out what I'm doing wrong, I would really appreciate it. Let me know if you need more info and I will supply that info.
Thanks in advance,
Kent Fonager
Answers
@KentFonager can you show us your entire Renderer class?
Hi Mitch
Thanks for your interest in helping me out. Here goes the complete code for the renderer class:
@KentFonager what is FormEntry inherited from?
Its inherited from View :
@KentFonager Make your Validator property setter:
Hi again Mitch
Thanks for holding onto me ;-)
Unfortunately I cannot insert that code in the code, is it is not recognized. I think the class somehow should use the "INotifyPropertyChanged" interface, right ?
Maybe I'm not using the correct design/pattern for a scenario like this ?
@KentFonager yes. that is entirely possible. BTW, you are going to a lot of work here. What exactly are you trying to accomplish?
I want an "Entry component" composed of multiple subcomponents like the actual textfield, some icons and other stuff, where we have an "external" validator (via the EventTrigger), that will change some visual stuff in the component (small fade animations).
So what i want is, that when the Event Trigger has run, I want to make that stuff in the component happend.
You follow me ?
By doing it with the event trigger, I can reuse the component, and wire up different types of validators like comparing for text length, is it a number only and so on ...
@KentFonager that's what I thought, just confirming.
But Mitch ... Am I doing it all "wrong" or ? How would one implement a scenario like that ? I cant really see that I should implement the properties like a "bindable model" class ? Seems like kinda overkill ?
@KentFonager I am not sure actually.
Would it be possible to create a sample project that contains the code snippets you have shown and attach the zip here so that I could test it on my machine?
Hi Mitch
I have now attached a sample project with the "component". I hope you maybe could figure out a way to make it work, as expected. What i want is that when the "trigger validator" has run, it calls the Setter on the "Validated" property, which in the end should trigger a "property change" in the platform renderer.
Thanks for helping out, I really appreciate it, Mitch :-D
Cheers,
Kent
And here is the file, ups ;-)
I changes some stuff and now I see the expected behaviour. I have attached the corrected demo project, if anyone should be interested in trying it out.