Ejemplo n.º 1
0
        public void DoubleTapped_Should_Not_Be_Rasied_if_Pressed_is_Handled()
        {
            Border border    = new Border();
            var    decorator = new Decorator
            {
                Child = border
            };
            var result = new List <string>();

            decorator.AddHandler(Border.PointerPressedEvent, (s, e) =>
            {
                result.Add("dp");
                e.Handled = true;
            });

            decorator.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("dr"));
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            decorator.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("ddt"));
            border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp"));
            border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));
            border.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("bdt"));

            _mouse.Click(border);
            _mouse.Down(border, clickCount: 2);

            Assert.Equal(new[] { "bp", "dp", "br", "dr", "bt", "dt", "bp", "dp" }, result);
        }
Ejemplo n.º 2
0
        public void DoubleTapped_Should_Follow_Pointer_Pressed_Released_Pressed()
        {
            Border border;
            var    decorator = new Decorator
            {
                Child = border = new Border()
            };
            var result = new List <string>();

            decorator.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("dp"));
            decorator.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("dr"));
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            decorator.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("ddt"));
            border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp"));
            border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));
            border.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("bdt"));

            border.RaiseEvent(new PointerPressedEventArgs());
            border.RaiseEvent(new PointerReleasedEventArgs());
            border.RaiseEvent(new PointerPressedEventArgs {
                ClickCount = 2
            });

            Assert.Equal(new[] { "bp", "dp", "br", "dr", "bt", "dt", "bp", "dp", "bdt", "ddt" }, result);
        }
Ejemplo n.º 3
0
        protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
        {
            base.OnApplyTemplate(e);

            _moduleDrop = e.NameScope.Get <Border>("PART_ModuleDrop");
            _fileDrop   = e.NameScope.Get <Border>("Part_FileDrop");

            _moduleDrop.AddHandler(DragDrop.DragOverEvent, DragOver);
            _moduleDrop.AddHandler(DragDrop.DragLeaveEvent, DragLeave);
            _fileDrop.AddHandler(DragDrop.DragOverEvent, DragOver);
            _fileDrop.AddHandler(DragDrop.DragLeaveEvent, DragLeave);

            switch (_typeDrop)
            {
            case TypeDrop.OnlyFile:
                _moduleDrop.IsVisible = false;

                _fileDrop.AddHandler(DragDrop.DropEvent, FileDrop);
                break;

            case TypeDrop.OnlyModule:
                _fileDrop.IsVisible = false;

                _moduleDrop.AddHandler(DragDrop.DropEvent, ModuleDrop);
                break;

            default:
                _fileDrop.AddHandler(DragDrop.DropEvent, FileDrop);
                _moduleDrop.AddHandler(DragDrop.DropEvent, ModuleDrop);
                break;
            }
        }
Ejemplo n.º 4
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            //ContentGrid = GetTemplateChild("ContentGrid") as Grid;
            RootGrid          = GetTemplateChild("RootGrid") as Grid;
            ContentBorder     = GetTemplateChild("ContentBorder") as Border;
            ShadowHost        = GetTemplateChild("ShadowHost") as Rectangle;
            LightDismissLayer = GetTemplateChild("LightDismissLayer") as Rectangle;
            BorderBackground  = GetTemplateChild("BorderBackground") as Rectangle;
            CloseButton       = GetTemplateChild("CloseButton") as Button;

            if (ContentBorder != null)
            {
                ContentBorder.SizeChanged += ContentBorder_SizeChanged;
                ContentBorder.AddHandler(PointerPressedEvent, new PointerEventHandler(ContentBorder_PointerPressed), true);
                ContentBorder.AddHandler(PointerReleasedEvent, new PointerEventHandler(ContentBorder_PointerReleased), true);
                ContentBorder.AddHandler(PointerCanceledEvent, new PointerEventHandler(ContentBorder_PointerCanceled), true);
            }
            if (LightDismissLayer != null)
            {
                LightDismissLayer.Tapped += LightDismissLayer_Tapped;
                LightDismissLayerVisual   = ElementCompositionPreview.GetElementVisual(LightDismissLayer);
            }
            if (CloseButton != null)
            {
                CloseButton.Click += CloseButton_Click;
            }
            UpdateIsOpen();
        }
Ejemplo n.º 5
0
        private void AddHandlers(
            Decorator decorator,
            Border border,
            IList <string> result,
            bool markHandled)
        {
            decorator.AddHandler(Border.PointerPressedEvent, (s, e) =>
            {
                result.Add("dp");

                if (markHandled)
                {
                    e.Handled = true;
                }
            });

            decorator.AddHandler(Border.PointerReleasedEvent, (s, e) =>
            {
                result.Add("dr");

                if (markHandled)
                {
                    e.Handled = true;
                }
            });

            border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp"));
            border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br"));

            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            decorator.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("ddt"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));
            border.AddHandler(Gestures.DoubleTappedEvent, (s, e) => result.Add("bdt"));
        }
 private void OnBorderLoaded(object sender, RoutedEventArgs e)
 {
     border.AddHandler(UIElement.MouseDownEvent, new RoutedEventHandler(OnMouseDown), true);
     border.AddHandler(UIElement.MouseUpEvent, new RoutedEventHandler(OnMouseUp), true);
     border.AddHandler(UIElement.MouseMoveEvent, new RoutedEventHandler(OnMouseMove), true);
     parentCanvas = border.Parent as Canvas;
 }
 private void OnBorderLoaded(object sender, RoutedEventArgs e)
 {
     border.AddHandler(UIElement.MouseDownEvent, new RoutedEventHandler(OnMouseDown), true);
     border.AddHandler(UIElement.MouseUpEvent, new RoutedEventHandler(OnMouseUp), true);
     border.AddHandler(UIElement.MouseMoveEvent, new RoutedEventHandler(OnMouseMove), true);
     parentGrid   = border.Parent as Grid;
     parentCanvas = parentGrid.Parent as Canvas;
     direction    = SizeDirectionBorderProperty.GetValue(border);
 }
Ejemplo n.º 8
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _dragWidget = (Border)GetTemplateChild("PART_DragWidget");
            if (_dragWidget != null)
            {
                _dragWidget.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(HeaderLeftMouseButtonDown), true);
                _dragWidget.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderMouseLeftButtonUp), true);
                _dragWidget.MouseMove += (o, e) => HeaderMouseMove(e);
            }

            CloseButton = (Button)GetTemplateChild("PART_CloseButton");
            if (CloseButton != null)
            {
                CloseButton.Click += (o, e) => Close();
            }

            WindowRoot = GetTemplateChild("PART_WindowRoot") as Grid;
            WindowRoot.RenderTransform = _moveTransform;

            _parentContainer = VisualTreeHelper.GetParent(this) as FrameworkElement;
            _parentContainer.LayoutUpdated += ParentContainer_LayoutUpdated;
            _parentContainer.SizeChanged   += ParentContainer_SizeChanged;

            //initialize our modal background width/height
            _modalLayer.Height = _parentContainer.ActualHeight;
            _modalLayer.Width  = _parentContainer.ActualWidth;

            //this is for XBAP applications only. When inside an XBAP the parent container has no height or width until it has loaded. Therefore
            //we need to handle the loaded event and reposition the window.
            if (System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted)
            {
                _parentContainer.Loaded += (o, e) =>
                {
                    ExecuteOpen();
                };
            }

            _root = GetTemplateChild("Root") as Grid;

#if VS2008
            FocusVisualStyle = null;
#else
            Style focusStyle = _root.Resources["FocusVisualStyle"] as Style;
            if (focusStyle != null)
            {
                Setter focusStyleDataContext = new Setter(Control.DataContextProperty, this);
                focusStyle.Setters.Add(focusStyleDataContext);
                FocusVisualStyle = focusStyle;
            }
#endif
            _root.Children.Add(_modalLayerPanel);
        }
Ejemplo n.º 9
0
        public override void OnApplyTemplate()
        {
            if (IsInDesignMode)
            {
                return;
            }
            if (this.Header == null)
            {
                var dictionary = Application.LoadComponent(new Uri("/Neumann.TouchControls;component/FlyoutMessageBar.xaml", UriKind.Relative)) as ResourceDictionary;
                if (dictionary != null && dictionary.Contains("FlyoutMessageBarDefaultHeader"))
                {
                    this.Header = dictionary["FlyoutMessageBarDefaultHeader"];
                }
            }
            var closeImage = this.GetTemplateChild("PART_CloseImage") as Image;

            if (closeImage != null)
            {
                closeImage.AddHandler(Image.MouseEnterEvent, new MouseEventHandler(this.OnCloseMouseEnter));
                closeImage.AddHandler(Image.MouseLeaveEvent, new MouseEventHandler(this.OnCloseMouseLeave));
                closeImage.AddHandler(Image.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.OnCloseMouseDown));
                closeImage.AddHandler(Image.MouseLeftButtonUpEvent, new MouseButtonEventHandler(this.OnCloseMouseUp));
            }
            _border = this.GetTemplateChild("border") as Border;
            if (_border != null)
            {
                _border.AddHandler(Border.MouseLeftButtonUpEvent, new MouseButtonEventHandler(this.OnMouseUp));
            }
            _openAnimation  = this.GetTemplateChild("openAnimation") as DoubleAnimation;
            _closeAnimation = this.GetTemplateChild("closeAnimation") as DoubleAnimation;
            this.SetTransformationDirection();
            this.SetGeometry();
        }
Ejemplo n.º 10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            _win             = new Window();
            _win.WindowStyle = WindowStyle.None;
            _win.Width       = 500;
            _win.Height      = 400;
            _win.Top         = 0;
            _win.Left        = 0;

            _root            = new Border();
            _root.Width      = _win.Width;
            _root.Height     = _win.Height;
            _root.Background = new SolidColorBrush(Colors.Red);
            _win.Content     = _root;
            _root.AddHandler(Mouse.MouseDownEvent, new MouseButtonEventHandler(OnMouseDown), false);

            _win.Title = "Window DragMove test";
            _win.Show();

            _oldPos      = new Point(_win.Left, _win.Top);
            _delta       = new Point(100, 100);
            _correction  = new Point(10, 10);
            _expectedPos = new Point(_oldPos.X + _delta.X - _correction.X, _oldPos.Y + _delta.Y - _correction.Y);

            Dispatcher.CurrentDispatcher.BeginInvoke(
                DispatcherPriority.Background,
                new DispatcherOperationCallback(DragMoveTest),
                this);

            base.OnStartup(e);
        }
Ejemplo n.º 11
0
        public void Tapped_Should_Be_Raised_Even_When_PointerPressed_Handled()
        {
            Border border    = new Border();
            var    decorator = new Decorator
            {
                Child = border
            };
            var result = new List <string>();

            border.AddHandler(Border.PointerPressedEvent, (s, e) => e.Handled = true);
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));

            _mouse.Click(border);

            Assert.Equal(new[] { "bt", "dt" }, result);
        }
Ejemplo n.º 12
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);
            Border iconBorder = e.NameScope.Find <Border>("PART_IconBorder");

            if (iconBorder != null)
            {
                iconBorder.AddHandler(Border.PointerReleasedEvent, IconBorder_MouseLeftButtonUp, RoutingStrategies.Tunnel);
            }
        }
Ejemplo n.º 13
0
        public void When_SubscribingUsingAddHandlerTwice_And_Unregister()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var root = new Border();

            void OnTapped(object snd, TappedRoutedEventArgs evt) => events.Add((snd, evt));

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);

            root.RemoveHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped);

            var evt1 = new TappedRoutedEventArgs();

            root.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeTrue();
            events.Should().HaveCount(1);
        }
Ejemplo n.º 14
0
        public PlaylistItemControl()
        {
            InitializeComponent();

            SetupDnd();

            // TODO ハンドラ登録のやり方が分からず、ネットで調査した内容をそのまま利用している
            m_DragDropBorder = this.Find <Border>("DragDropBorder");
            m_DragDropBorder.AddHandler(PointerPressedEvent, DoDrag);
        }
Ejemplo n.º 15
0
        public void Tapped_Should_Follow_Pointer_Pressed_Released()
        {
            Border border    = new Border();
            var    decorator = new Decorator
            {
                Child = border
            };
            var result = new List <string>();

            decorator.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("dp"));
            decorator.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("dr"));
            decorator.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("dt"));
            border.AddHandler(Border.PointerPressedEvent, (s, e) => result.Add("bp"));
            border.AddHandler(Border.PointerReleasedEvent, (s, e) => result.Add("br"));
            border.AddHandler(Gestures.TappedEvent, (s, e) => result.Add("bt"));

            _mouse.Click(border);

            Assert.Equal(new[] { "bp", "dp", "br", "dr", "bt", "dt" }, result);
        }
        /* Creates a dropable UI border */
        public UIElement dropableBorder(int rowNum, int colNum, BrushConverter bc)
        {
            Border cbd = new Border();

            cbd.Background          = Brushes.Transparent;
            cbd.BorderBrush         = (Brush)bc.ConvertFromString("#8D8D8D");
            cbd.BorderThickness     = new Thickness(1.0);
            cbd.Name                = "cell" + rowNum + "_" + colNum;
            cbd.MinWidth            = 75;
            cbd.MinHeight           = 75;
            cbd.HorizontalAlignment = HorizontalAlignment.Stretch;
            cbd.VerticalAlignment   = VerticalAlignment.Stretch;
            cbd.AddHandler(Border.DropEvent, new DragEventHandler(Border_Drop));

            return(cbd);
        }
Ejemplo n.º 17
0
        public void When_SubscribingUsingAddHandler()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var root = new Border();

            void OnTapped(object snd, TappedRoutedEventArgs evt) => events.Add((snd, evt));

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);

            var evt1 = new TappedRoutedEventArgs();

            root.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeTrue();

            events.Should().HaveCount(1)
            .And.ContainSingle(x => x.sender == root && x.args == evt1);
        }
        public LayoutEditorPage()
        {
            InitializeComponent();

            BrushConverter bc = new BrushConverter();

            for (int i = 0; i < 10; i++)
            {
                RowDefinition rd = new RowDefinition();
                rd.Height = new GridLength(1.0, GridUnitType.Star);
                visualEditorGrid.RowDefinitions.Add(rd);

                /*Border rbd = new Border();
                 * rbd.Background = Brushes.Transparent;
                 * rbd.BorderBrush = (Brush)bc.ConvertFromString("#8D8D8D");
                 * rbd.BorderThickness = new Thickness(1.0);
                 * Grid.SetRow(rbd, i);
                 * visualEditorGrid.Children.Add(rbd);*/

                for (int j = 0; j < 10; j++)
                {
                    ColumnDefinition cd = new ColumnDefinition();
                    cd.Width = new GridLength(1.0, GridUnitType.Star);
                    visualEditorGrid.ColumnDefinitions.Add(cd);

                    Border cbd = new Border();
                    cbd.Background          = Brushes.Transparent;
                    cbd.BorderBrush         = (Brush)bc.ConvertFromString("#8D8D8D");
                    cbd.BorderThickness     = new Thickness(1.0);
                    cbd.Name                = "cell" + i + "_" + j;
                    cbd.MinWidth            = 75;
                    cbd.MinHeight           = 75;
                    cbd.HorizontalAlignment = HorizontalAlignment.Stretch;
                    cbd.VerticalAlignment   = VerticalAlignment.Stretch;
                    cbd.AddHandler(Border.DropEvent, new DragEventHandler(Border_Drop));

                    Grid.SetRow(cbd, i);
                    Grid.SetColumn(cbd, j);
                    visualEditorGrid.Children.Add(cbd);
                }
            }
        }
Ejemplo n.º 19
0
        public void When_SubscribingUsingAddHandler_WithHandlesToo_And_BubblingInNativeCode_EatenByPlatform()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var child2 = new Border
            {
                Name = "child2"
            };
            var child1 = new Border
            {
                Child = child2,
                Name  = "child1"
            };
            var root = new Border
            {
                Child = child1,
                Name  = "root"
            };

            void OnTapped(object snd, TappedRoutedEventArgs evt)
            {
                events.Add((snd, evt));
                evt.Handled = true;
            }

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, true);
            child2.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, true);

            root.Measure(new Size(1, 1));

            var evt1 = new TappedRoutedEventArgs()
            {
                CanBubbleNatively = true
            };

            child1.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeFalse();
            // Here the "platform" is eating the native bubbling event, so no handlers should receive it.

            events.Should().HaveCount(0);
        }
Ejemplo n.º 20
0
        public void When_SubscribingUsingAddHandler_WithHandlesToo_And_BubblingInNativeCode_SetToBubbleInManaged_EatenByPlatform()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var child2 = new Border
            {
                Name = "child2"
            };
            var child1 = new Border
            {
                Child = child2,
                Name  = "child1"
            };
            var root = new Border
            {
                Child = child1,
                Name  = "root",
                EventsBubblingInManagedCode = RoutedEventFlag.Tapped
            };

            void OnTapped(object snd, TappedRoutedEventArgs evt)
            {
                events.Add((snd, evt));
                evt.Handled = true;
            }

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, true);
            child1.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, true);

            root.Measure(new Size(1, 1));

            var evt1 = new TappedRoutedEventArgs()
            {
                CanBubbleNatively = true
            };

            child2.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeTrue();

            events.Should().HaveCount(2);             // bubbling in managed code
        }
Ejemplo n.º 21
0
        public void When_SubscribingUsingAddHandler_And_BubblingInNativeCode()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var child2 = new Border
            {
                Name = "child2"
            };
            var child1 = new Border
            {
                Child = child2,
                Name  = "child1"
            };
            var root = new Border
            {
                Child = child1,
                Name  = "root"
            };

            void OnTapped(object snd, TappedRoutedEventArgs evt)
            {
                events.Add((snd, evt));
                evt.Handled = true;
            }

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);
            child1.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);

            root.Measure(new Size(1, 1));

            var evt1 = new TappedRoutedEventArgs()
            {
                CanBubbleNatively = true
            };

            child2.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeFalse();

            events.Should().HaveCount(0);
        }
Ejemplo n.º 22
0
        public void When_SubscribingUsingAddHandler_And_BubblingInManagedCode()
        {
            var events = new List <(object sender, TappedRoutedEventArgs args)>();

            var child2 = new Border
            {
                Name = "child2"
            };
            var child1 = new Border
            {
                Child = child2,
                Name  = "child1"
            };
            var root = new Border
            {
                Child = child1,
                Name  = "root"
            };

            void OnTapped(object snd, TappedRoutedEventArgs evt)
            {
                events.Add((snd, evt));
                evt.Handled = true;
            }

            root.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);
            child1.AddHandler(UIElement.TappedEvent, (TappedEventHandler)OnTapped, false);

            root.Measure(new Size(1, 1));

            var evt1 = new TappedRoutedEventArgs();

            child2.RaiseEvent(UIElement.TappedEvent, evt1).Should().BeTrue();

            events.Should().HaveCount(1)
            .And.ContainSingle(x => x.sender == child1 && x.args == evt1);
        }
Ejemplo n.º 23
0
        private void AddCar(Car c)
        {
            Border border = new Border
            {
                Style = (Style)FindResource("BorderCar")
            };
            RoutedEventHandler h = delegate(object sender, RoutedEventArgs e) { ShowDetails_Click(sender, e, c); };

            border.AddHandler(Border.MouseDownEvent, h);

            StackPanel panel = new StackPanel();

            Image image        = new Image();
            var   fullFilePath = c.Image;

            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.UriSource = new Uri(fullFilePath, UriKind.Absolute);
            bitmap.EndInit();

            image.Source = bitmap;
            image.Width  = 150;
            image.SetValue(Grid.RowProperty, 0);

            TextBlock textblockName = new TextBlock
            {
                Text = c.Brand.Name + " " + c.Name,
                HorizontalAlignment = HorizontalAlignment.Center,
                FontSize            = 12,
                FontWeight          = FontWeights.Bold,
                Margin = new Thickness(2, 2, 2, 2)
            };

            textblockName.SetValue(Grid.RowProperty, 1);

            TextBlock textblockPrice = new TextBlock
            {
                Text = "CHF " + c.Price + " exkl. MwST.",
                HorizontalAlignment = HorizontalAlignment.Center
            };

            textblockPrice.SetValue(Grid.RowProperty, 2);

            Button button = new Button
            {
                Content = "Konfigurieren",
                Margin  = new Thickness(0, 10, 0, 0),
                Width   = 150,
                Style   = (Style)FindResource("WhiteButtonBorder")
            };

            button.Click += delegate(object sender, RoutedEventArgs e) { ButtonConfigure_Click(sender, e, c); };
            button.SetValue(Grid.RowProperty, 3);

            panel.Children.Add(image);
            panel.Children.Add(textblockName);
            panel.Children.Add(textblockPrice);
            panel.Children.Add(button);

            border.Child = panel;
            border.SetValue(Grid.ColumnProperty, x);
            border.SetValue(Grid.RowProperty, y);
            CarList.Children.Add(border);

            // If there are more than 3 cars in one row go to the next row
            if (x < 2)
            {
                x++;
            }
            else
            {
                x = 0;
                y++;
                CarList.RowDefinitions.Add(new RowDefinition());
            }
        }