Пример #1
0
        protected override void LoadContent()
        {
            var spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var spriteFontAdapter  = new SpriteFontAdapter(this.Game.Content.Load <SpriteFont>("SpriteFont"));
            var primitivesService  = new PrimitivesService(this.GraphicsDevice);
            var renderer           = new Renderer(spriteBatchAdapter, primitivesService);

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            var bindingClass  = new BindingClass();
            var bindingClass2 = new BindingClass2();

            var border = new Border
            {
                Background = new SolidColorBrush(Colors.LightGray),
                Child      = new TextBlock(spriteFontAdapter)
                {
                    Text = "Click"
                }
            };

            var toggleButton = new ToggleButton {
                Content = border
            };

            border.Bind(Border.BackgroundProperty, bindingClass2.BackgroundColor);

            toggleButton.Bind(ToggleButton.IsCheckedProperty, bindingClass2.IsChecked, bindingClass2.IsChecked);

            this.rootElement.Content = toggleButton;
        }
        void UpdateTemplate()
        {
            if (Node != null)
            {
                bindings.Add(expander.Bind(ToggleButton.IsVisibleProperty, new Binding("ShowExpander")
                {
                    Source = Node
                }));
                bindings.Add(expander.Bind(ToggleButton.IsCheckedProperty, new Binding("IsExpanded")
                {
                    Source = Node
                }));
                bindings.Add(icon.Bind(ContentPresenter.IsVisibleProperty, new Binding("ShowIcon")
                {
                    Source = Node
                }));
                bindings.Add(checkBoxContainer.Bind(Border.IsVisibleProperty, new Binding("IsCheckable")
                {
                    Source = Node
                }));
                bindings.Add(checkBox.Bind(CheckBox.IsCheckedProperty, new Binding("IsChecked")
                {
                    Source = Node
                }));
                bindings.Add(textContainer.Bind(Border.IsVisibleProperty, new Binding("IsEditing")
                {
                    Source = Node, Converter = BoolConverters.Inverse
                }));
                bindings.Add(textContent.Bind(ContentPresenter.ContentProperty, new Binding("Text")
                {
                    Source = Node
                }));
                RaisePropertyChanged(IconProperty, null, Icon);
            }

            spacer.Width = CalculateIndent();

            if (ParentTreeView.Root == Node && !ParentTreeView.ShowRootExpander)
            {
                expander.IsVisible = false;
            }
            else
            {
                expander.ClearValue(IsVisibleProperty);
            }
        }
Пример #3
0
        public void ToggleButton_Is_Checked_Binds_To_Bool()
        {
            var toggleButton = new ToggleButton();
            var source       = new Class1();

            toggleButton.DataContext = source;
            toggleButton.Bind(ToggleButton.IsCheckedProperty, new Binding("Foo"));

            source.Foo = true;
            Assert.True(toggleButton.IsChecked);

            source.Foo = false;
            Assert.False(toggleButton.IsChecked);
        }
        public void ToggleButton_ThreeState_Checked_Binds_To_Nullable_Bool()
        {
            var threeStateButton = new ToggleButton();
            var source           = new Class1();

            threeStateButton.DataContext = source;
            threeStateButton.Bind(ToggleButton.IsCheckedProperty, new Binding(nameof(Class1.NullableFoo)));

            source.NullableFoo = true;
            Assert.True(threeStateButton.IsChecked);

            source.NullableFoo = false;
            Assert.False(threeStateButton.IsChecked);

            source.NullableFoo = null;
            Assert.Null(threeStateButton.IsChecked);
        }
Пример #5
0
        protected override void LoadContent()
        {
            var spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var spriteFontAdapter  = new SpriteFontAdapter(this.Game.Content.Load <SpriteFont>("SpriteFont"));
            var renderer           = new Renderer(spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            // Setup Layout
            var cardImage = new Image
            {
                Stretch = Stretch.None
            };

            var cardToggleButton = new ToggleButton
            {
                Content = cardImage,
                Margin  = new Thickness(10)
            };

            var resetButton = new Button
            {
                Content =
                    new Border
                {
                    Background = new SolidColorBrush(Colors.LightGray),
                    Child      = new TextBlock(spriteFontAdapter)
                    {
                        Text   = "Reset",
                        Margin = new Thickness(10)
                    }
                },
                Margin = new Thickness(10),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            var stackPanel = new StackPanel
            {
                Children =
                {
                    cardToggleButton,
                    resetButton
                }
            };

            this.rootElement.Content = stackPanel;

            // Setup Data Binding
            var faceDownImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load <Texture2D>("FaceDown")));
            var faceUpImage   = new TextureImage(new Texture2DAdapter(this.Game.Content.Load <Texture2D>("FaceUp")));

            var card = new Card(faceDownImage, faceUpImage);

            cardImage.Bind(
                Image.SourceProperty,
                BindingFactory.CreateOneWay <Card, ImageSource>(card, d => d.CardImage));

            cardToggleButton.Bind(
                ToggleButton.IsCheckedProperty,
                BindingFactory.CreateTwoWay(card, d => d.IsCardFaceUp));

            resetButton.Click += (sender, args) => card.Reset();
        }