Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@yakumomo

XamarinのBindingについて

More than 5 years have passed since last update.

XamarinのBindingでご質問

エクセルソフトの田淵さんがこんなことをつぶやいておられました。

まあ、こう考えたのですが。

実はこうである、と。

やってみた

まあ、確かにBinding難しいよなー。
とかつらつら考えながらコーディング。
できました。

BindingContextがミソ

    public class App : Xamarin.Forms.Application
    {
        Switch sw1;
        Switch sw2;
        Switch sw3;
        Entry ent;

        public App() {
            sw1 = new Switch () {
            };
            sw2 = new Switch () {
            };
            sw2.BindingContext = sw1;
            sw2.SetBinding (Switch.IsToggledProperty, new Binding ("IsToggled", BindingMode.OneWay));
            sw3 = new Switch () {
            };
            sw3.BindingContext = sw1;
            sw3.SetBinding (Switch.IsToggledProperty, new Binding ("IsToggled", BindingMode.OneWay));
            ent = new Entry () {
                Text = "Hello, world",
            };
            ent.BindingContext = sw1;
            ent.SetBinding (Entry.IsEnabledProperty, new Binding ("IsToggled", BindingMode.OneWay));
            MainPage = new ContentPage () {
                Content = new StackLayout() {
                    Padding = new Thickness(0, 20, 0,0),
                    Orientation = StackOrientation.Vertical,
                    Children = {
                        new StackLayout() {
                            Orientation = StackOrientation.Horizontal,
                            Children = {
                                sw1,
                                new Label() {
                                    Text = "<- switch this",
                                },
                            },
                        },
                        sw2,
                        sw3,
                        ent,
                    },
                },
            };
        }
    }

まあ要するに、先スイッチのBindingContextを元スイッチのオブジェクトにして仕舞えばいいわけですね。
XAMLだと…。
どうするかなぁ。

4
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
yakumomo
今のところ、AzureとXamarinとCoreOSとWindows10が好きです。 ここでは、実使用でのポイントをメモ。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?