Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Trouble creating a DataTrigger in C# (not XAML)

$
0
0

I'm having trouble creating a DataTrigger in C# (the project I'm working on isn't using XAML).

I'm trying to disable a button when the text length of a field is 0.

Here's the code:

        Entry emailEntry = new Entry
        {
            Placeholder = "email",
            Text = "",
            HorizontalOptions = LayoutOptions.Fill,
        };
        Button signInButton = new Button
        {
            Text = "sign in",
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };
    DataTrigger trigger = new DataTrigger(typeof(Button));
        Binding b = new Binding();
        b.Source = emailEntry;
        b.Path = "Text.Length";
        trigger.Binding = b;
        trigger.Value = "0";
        Setter s = new Setter();
        s.Property = Button.IsEnabledProperty;
        s.Value = false;
        trigger.Setters.Add(s);
        signInButton.Triggers.Add(trigger);

I tried making a test project with some simple XAML in it to set up this scenario (it works in XAML), and it looks like the trigger has the same values (via watch window) in both projects.

Any ideas?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>