Пример #1
0
    public static void Main()
    {
        // XAML string that defines the WPF controls
        string strXAML = @"
<Window
	xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
	xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
	x:Name=""Window"" Title=""Test program for Windows Presentation Framework"" WindowStartupLocation = ""CenterScreen""
	Width = ""800"" Height = ""400"" ShowInTaskbar = ""True"">
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height=""auto""></RowDefinition>
			<RowDefinition Height=""150""></RowDefinition>
		</Grid.RowDefinitions>
		<TextBlock TextAlignment=""Center"" Foreground=""Black"" FontSize=""40"" HorizontalAlignment=""Center"" Grid.Row=""0"" Grid.Column=""0"" >
	    <TextBlock.Effect><DropShadowEffect ShadowDepth=""4"" Color=""DarkGray"" BlurRadius=""4""/></TextBlock.Effect>
			<LineBreak/>Test program for <LineBreak/><LineBreak/>Windows Presentation Framework
		</TextBlock>
		<Button x:Name=""Knopf"" Height=""24"" Width=""72"" Content=""Click me"" ToolTip=""Left click exits program, right click makes button green"" Grid.Row=""1"" Grid.Column=""0"" />
	</Grid>
</Window>";

        // prepare XML document
        XmlDocument XAML = new XmlDocument();

        // read XAML string
        XAML.LoadXml(strXAML);
        // and convert to XML
        XmlNodeReader XMLReader = new XmlNodeReader(XAML);
        // generate WPF object tree
        Window objWindow;

        try
        {               // set XAML root object
            objWindow = (Window)XamlReader.Load(XMLReader);
        }
        catch
        {         // XamlReader generates an exception on error in XAML definition
            MessageBox.Show("Error while creating the WPF controls out of the XAML description", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            return;
        }

        // search button object in WPF tree
        System.Windows.Controls.Button objButton = (System.Windows.Controls.Button)objWindow.FindName("Knopf");

        // add eventhandler (the last parameter false means, that the handler is not called, when an event is already handled)
        objButton.AddHandler(FrameworkElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(Button_MouseLeftButtonUp), true);
        objButton.AddHandler(FrameworkElement.MouseRightButtonUpEvent, new MouseButtonEventHandler(Button_MouseRightButtonUp), false);
        objButton.MouseEnter += Button_MouseEnter;
        objButton.MouseLeave += Button_MouseLeave;

        // and show WPF window
        objWindow.ShowDialog();
    }
Пример #2
0
 public PlayAction(Button stopAudioButton)
 {
     stopAudioButton.AddHandler(Button.ClickEvent, new RoutedEventHandler(StopAudioButton_Click));
 }
Пример #3
0
        public override void OnApplyTemplate()
        {
            _controlBarGrid = Template.FindName("PART_ControlBarGrid", this) as Grid;
            _fadeInStoryboard = Template.Resources["FadeInStoryboard"] as Storyboard;
            _fadeOutStoryboard = Template.Resources["FadeOutStoryboard"] as Storyboard;

            MouseEnter += OnGadgetContainerMouseEnter;
            MouseLeave += OnGadgeContainerMouseLeave;
            PreviewMouseLeftButtonDown += OnGadgetContainerPreviewMouseLeftButtonDown;

            _closeButton = Template.FindName("PART_CloseButton", this) as Button;

            if (_closeButton != null)
            {
                _closeButton.AddHandler(MouseLeftButtonUpEvent, new RoutedEventHandler(OnCloseButtonClick), true);
            }

            _optionButton = Template.FindName("PART_OptionButton", this) as Button;

            if (_optionButton != null)
            {
                _optionButton.AddHandler(MouseLeftButtonUpEvent, new RoutedEventHandler(OnOptionButtonClick), true);
            }
        }
Пример #4
0
		private System.Windows.Controls.Button exitButton(int id)
		{
			System.Windows.Controls.Image img = new System.Windows.Controls.Image();
			BitmapImage image = new BitmapImage(new Uri("/Resources/delete.ico", UriKind.Relative));
			img.Source=image;
			
			StackPanel bsp = new StackPanel();
			bsp.Children.Add(img);
			
    		System.Windows.Controls.Button b = new System.Windows.Controls.Button();
    		b.AddHandler(System.Windows.Controls.Button.ClickEvent, new RoutedEventHandler(closeTab));
    		b.Content=bsp;
    		b.Height=16;
    		b.Width=16;
    		b.Padding = new Thickness(0, 0, 0, 0);
    		
    		Thickness thick = new Thickness();
    		thick.Bottom = 0;
    		thick.Top = 0;
    		thick.Left = 0;
    		thick.Right = 0;
    		SolidColorBrush scb = new SolidColorBrush();
    		scb.Color = Color.FromArgb(0,0,0,0);
    		
    		b.Background = scb;
    		b.BorderThickness = thick;
    		b.Name = "_" + id + "b";
    		
    		return b;
		}
Пример #5
0
 private void PrepareCompleteBox()
 {
     clearbutton = new Button();
     clearbutton.Style = FindResource("ClearButtonStyle") as Style;
     clearbutton.Content = "\xE10A";
     clearbutton.FontFamily = new FontFamily("Segoe UI Symbol");
     clearbutton.FontSize = 9;
     clearbutton.AddHandler(MouseDownEvent, new MouseButtonEventHandler(clearbutton_Click), true);
 }
Пример #6
0
        private void render()
        {
            Board.Children.Clear();
            for (int r = 0; r < board.numberRows; r++)
            {
                for (int c = 0; c < board.numberCols; c++)
                {
                    Grid cell = new Grid();
                    if (board.boardSpace(r, c).isMoveOption)
                    {
                        cell.Background = moveOption;
                        Button button = new Button();
                        button.Opacity = 0.0;
                        button.AddHandler(Button.ClickEvent, new RoutedEventHandler(MoveOption_Click));
                        Board.Children.Add(cell);
                        cell.Children.Add(button);
                    }
                    else
                    {
                        switch (board.boardSpace(r, c).tileTerrain)
                        {
                            case 0: //grass tile
                                cell.Background = grass;
                                Board.Children.Add(cell);
                                break;
                            case 1: //mountain tile
                                cell.Background = mountain;
                                Board.Children.Add(cell);
                                break;
                            case 2: //water tile
                                cell.Background = water;
                                Board.Children.Add(cell);
                                break;
                            case 3: //swamp tile
                                cell.Background = swamp;
                                Board.Children.Add(cell);
                                break;
                        }
                    }

                    if(board.boardSpace(r,c).containsCharacter() == true)
                    {
                        if (board.boardSpace(r, c).tileCharacter.GetType() == typeof(GameBoard.Player))
                        {
                            Ellipse circle = new Ellipse();
                            Button button = new Button();
                            circle.Fill = black;
                            button.Opacity = 0.0;
                            button.AddHandler(Button.ClickEvent, new RoutedEventHandler(Player_Click));
                            cell.Children.Add(circle);
                            cell.Children.Add(button);
                        }
                        else if(board.boardSpace(r, c).tileCharacter.GetType() == typeof(GameBoard.Enemy))
                        {
                            Ellipse circle = new Ellipse();
                            circle.Fill = red;
                            cell.Children.Add(circle);
                        }
                    }
                }
            }
        }