Nested Button content : Button « Windows Presentation Foundation « C# / CSharp Tutorial






<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WpfApplication1" Height="300" Width="300" WindowStartupLocation="CenterScreen">
  <StackPanel>
    <Button Name="btnClickMe" Height="75" Width = "250" Click ="btnClickMe_Clicked">
      <StackPanel Orientation ="Horizontal">
        <Label Height="50" FontSize ="20">Fancy Button!</Label>
        <Canvas Height ="50" Width ="100" >
          <Ellipse Name = "outerEllipse" Fill ="Green" Height ="25" 
                   MouseDown ="outerEllipse_MouseDown"
                   PreviewMouseDown ="outerEllipse_PreviewMouseDown"
                   Width ="50" Cursor="Hand" Canvas.Left="25" Canvas.Top="12"/>
          <Ellipse Name = "innerEllipse" Fill ="Yellow" Height = "15" Width ="36"
                        Canvas.Top="17" Canvas.Left="32"/>
        </Canvas>
      </StackPanel>
    </Button>
  </StackPanel>
</Window>
//File:Window.xaml.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WpfApplication1
{
  public partial class MainWindow : System.Windows.Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    public void btnClickMe_Clicked(object sender, RoutedEventArgs e)
    {
      Console.WriteLine("Button Click event fired!");
    }

    public void outerEllipse_MouseDown(object sender, RoutedEventArgs e)
    {
      Console.WriteLine("MouseDown event fired!");
      e.Handled = false;
    }

    public void outerEllipse_PreviewMouseDown(object sender, RoutedEventArgs e)
    {
      Console.WriteLine("PreviewMouseDown event fired!");
      e.Handled = false;
    }
  }
}
WPF Nested Button Content








24.1.Button
24.1.1.Put Button onto a GridPut Button onto a Grid
24.1.2.Add buttons to a Canvas with codeAdd buttons to a Canvas with code
24.1.3.Set Default Button for a WindowSet Default Button for a Window
24.1.4.Use TextBox as Button ContentUse TextBox as Button Content
24.1.5.The button and text block are up-side down in the custom coordinate system.The button and text block are up-side down in the custom coordinate system.
24.1.6.Change Button Alignment, Margin, FontSize and Padding in Style SettingChange Button Alignment, Margin, FontSize and Padding in Style Setting
24.1.7.Gradient Button Background by Rectangle and LinearGradientBrushGradient Button Background by Rectangle and LinearGradientBrush
24.1.8.Rotate a Button for 35 degreesRotate a Button for 35 degrees
24.1.9.Set VerticalAlignment/HorizontalAlignment for a ButtonSet VerticalAlignment/HorizontalAlignment for a Button
24.1.10.Button with Inline Property TriggerButton with Inline Property Trigger
24.1.11.Add a button control and a text block to the canvasAdd a button control and a text block to the canvas
24.1.12.Nested Button contentNested Button content