コード例 #1
0
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            // You can provide the list of choices by code, or by comma separated values in UXML
            // <DropdownField .... choices="Option 1,Option 2,Option 3" .... />
            var choices = new List <string> {
                "Option 1", "Option 2", "Option 3"
            };

            // Get a reference to the dropdown field from UXML and assign it its value.
            var uxmlField = container.Q <DropdownField>("the-uxml-field");

            uxmlField.choices = choices;
            uxmlField.value   = choices[0];

            // Create a new dropdown with the same choices, disable it, and give it a style class.
            var csharpField = new DropdownField("C# Field", choices, 0);

            csharpField.SetEnabled(false);
            csharpField.AddToClassList("some-styled-field");
            container.Add(csharpField);

            // Mirror value of uxml field into the C# field.
            uxmlField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                csharpField.value = evt.newValue;
            });
            /// </sample>
        }