Simple memo of the guy used when building XAML

1 minute read


Notes on building a UI for WPF in XAML
There is also a copy-and-paste summary of the results of searching and searching.

Hide the window frame of the APP and make it transparent

Hide the bar that closes the APP and set it so that there is no APP frame

WindowStyle : None
AllowTransparency : true

Create your own bar such as close APP from custom control

I want to control APP expansion and movement with my own APP header
When I made it a custom control, it did not work because there was no Window, so make a note of the countermeasure

public static class WindowUtil
  public static Window GetWindow(this DependencyObject element)
    return Window.GetWindow(element);
private void OnClose(object sender, RoutedEventArgs e)
  var window = ((FrameworkElement)sender).GetWindow();

private void OnMove(object sender, MouseButtonEventArgs e)
  var window = ((FrameworkElement)sender).GetWindow();

private void OnMaximam(object sender, RoutedEventArgs e)
  var window = ((FrameworkElement)sender).GetWindow();
  window.WindowState = window.WindowState != WindowState.Maximized ? WindowState.Maximized : WindowState.Normal;

private void OnMimimam(object sender, RoutedEventArgs e)
  var window = ((FrameworkElement)sender).GetWindow();
  window.WindowState = window.WindowState != WindowState.Minimized ? WindowState.Minimized : WindowState.Normal;

Change the appearance of the button

You can draw shapes on the canvas in a language like SVG
This is convenient, it feels like you can do the same as SVG

<Style TargetType="Button">
  <!--Set to true to not get any properties from the themes.-->
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="Button">
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"

Transfer properties to custom control XAML

public class ClockControl: UserControl
        public static readonly DependencyProperty CityProperty = DependencyProperty.Register
                 new PropertyMetadata(string.Empty)

        public string City
            get { return (string)GetValue(CityProperty); }
            set { SetValue(CityProperty, value); }

        public ClockControl()


Responsive with grid layout

Those with * feel like they are growing

      <RowDefinition Height="1080*"/>
      <ColumnDefinition Width="240*"/>
      <ColumnDefinition Width="240*"/>
      <ColumnDefinition Width="240*"/>
  <StackPanel Grid.Column="0"></StackPanel>
  <StackPanel Grid.Column="1"></StackPanel>
  <StackPanel Grid.Column="3"></StackPanel>

Reference site

Responsive layout in XAML

How do you pass parameters from xaml?

ControlTemplate class

How to: Draw an Ellipse or a Circle

Create a WPF app without a window border

[WPF] How to get Window from the included content?