Beispiel #1
0
        private void CreateMap(int width, int height, int cellSize)
        {
            var beginState = Game.CreateMap(width, height);

            appViewModel.Game.SetMap(beginState);

            for (int j = 0; j < height; j++)
            {
                Map.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(cellSize)
                });
            }
            for (int i = 0; i < width; i++)
            {
                Map.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(cellSize)
                });
            }

            Map.Width  = width * cellSize;
            Map.Height = height * cellSize;
            Height     = Map.Height + 40 + ToolBar.Height;
            Width      = Map.Width + 15;
            CenterWindow();

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int x     = i;
                    int y     = j;
                    var shape = new Ellipse()
                    {
                        Width  = cellSize,
                        Height = cellSize,
                    };
                    Map.Children.Add(shape);
                    Grid.SetRow(shape, x);
                    Grid.SetColumn(shape, y);

                    var trigger       = new Microsoft.Xaml.Behaviors.EventTrigger("MouseDown");
                    var commandAction = new InvokeCommandAction()
                    {
                        Command          = appViewModel.ToggleCommand,
                        CommandParameter = beginState[x, y],
                    };
                    trigger.Actions.Add(commandAction);
                    Interaction.GetTriggers(shape).Add(trigger);

                    var binding = new Binding
                    {
                        Source = beginState[x, y],
                        Path   = new PropertyPath("State")
                    };
                    shape.SetBinding(Shape.FillProperty, binding);
                }
            }
        }
Beispiel #2
0
        internal static void SetEventBinding(this Window window, string eventName, string commandName)
        {
            Microsoft.Xaml.Behaviors.EventTrigger trigger = new Microsoft.Xaml.Behaviors.EventTrigger(eventName);
            EventToCommand action = new EventToCommand();

            BindingOperations.SetBinding(action, EventToCommand.CommandProperty, new Binding(commandName));
            trigger.Actions.Add(action);
            Interaction.GetTriggers(window).Add(trigger);
        }
Beispiel #3
0
        private void BindLoadDataEvent()
        {
            var ev = new Microsoft.Xaml.Behaviors.EventTrigger()
            {
                EventName = "Loaded"
            };

            ev.SourceObject = this;
            var callMethod = new CallMethodAction {
                MethodName = "LoadData"
            };
            var binding = new Binding();

            BindingOperations.SetBinding(callMethod, CallMethodAction.TargetObjectProperty, binding);
            ev.Actions.Add(callMethod);

            Interaction.GetTriggers(this).Add(ev);
        }
Beispiel #4
0
        private void SetTriggerToTumbler(Tumbler T, string EventName, string Command, object Parametr)
        {
            var invokeCommandAction = new InvokeCommandAction {
                CommandParameter = Parametr
            };
            var binding = new Binding {
                Path = new PropertyPath(Command)
            };

            BindingOperations.SetBinding(invokeCommandAction, InvokeCommandAction.CommandProperty, binding);

            var eventTrigger = new Microsoft.Xaml.Behaviors.EventTrigger {
                EventName = EventName
            };

            eventTrigger.Actions.Add(invokeCommandAction);

            var triggers = Interaction.GetTriggers(T);

            triggers.Add(eventTrigger);
        }