Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Non Rectangular Window in WPF Help

Non Rectangular Window in WPF Help

Scheduled Pinned Locked Moved WPF
wpfhelpcsharpdotnetcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    snouto
    wrote on last edited by
    #1

    Hello everybody . i am trying to make non rectangular window in wpf , using Rectangle with rounded corners i have already done so , but the problem , i can't add controls on the window anymore . i don't know why . here is the code .

    <Window x:Class="TestingPOS.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestingPOS.Controls"
    x:Name="MainWindow"

    Title="Window1" Height="600" Width="600" Background="Transparent" AllowsTransparency="True" WindowStyle="None" MouseLeftButtonDown="Window\_MouseLeftButtonDown">
    
    <Window.Template>
        <ControlTemplate>
            <Rectangle Stroke="Black" RadiusX="97.5" RadiusY="97.5" Canvas.Top="36">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="Black" Offset="0"/>
                        <GradientStop Color="White" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </ControlTemplate>
    </Window.Template>
    

    </Window>

    this code makes the window with rounded corners but i have made a user control login screen that i need to insert onto the window , the form doesn't accept any controls even like button or textbox how can i do that task Please help !

    Human knowledge belongs to the world.

    I 1 Reply Last reply
    0
    • S snouto

      Hello everybody . i am trying to make non rectangular window in wpf , using Rectangle with rounded corners i have already done so , but the problem , i can't add controls on the window anymore . i don't know why . here is the code .

      <Window x:Class="TestingPOS.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:TestingPOS.Controls"
      x:Name="MainWindow"

      Title="Window1" Height="600" Width="600" Background="Transparent" AllowsTransparency="True" WindowStyle="None" MouseLeftButtonDown="Window\_MouseLeftButtonDown">
      
      <Window.Template>
          <ControlTemplate>
              <Rectangle Stroke="Black" RadiusX="97.5" RadiusY="97.5" Canvas.Top="36">
                  <Rectangle.Fill>
                      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                          <GradientStop Color="Black" Offset="0"/>
                          <GradientStop Color="White" Offset="1"/>
                      </LinearGradientBrush>
                  </Rectangle.Fill>
              </Rectangle>
          </ControlTemplate>
      </Window.Template>
      

      </Window>

      this code makes the window with rounded corners but i have made a user control login screen that i need to insert onto the window , the form doesn't accept any controls even like button or textbox how can i do that task Please help !

      Human knowledge belongs to the world.

      I Offline
      I Offline
      Insincere Dave
      wrote on last edited by
      #2

      You need a ContentPresenter in your ControlTemplate and set the TargetType of the ControlTemplate too.

      <Window.Template>
          <ControlTemplate TargetType="{x:Type Window}">
              <Grid>
                  <Rectangle Stroke="Black" RadiusX="97.5" RadiusY="97.5" >
                      <Rectangle.Fill>
                          <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                              <GradientStop Color="Black" Offset="0"/>
                              <GradientStop Color="White" Offset="1"/>
                          </LinearGradientBrush>
                      </Rectangle.Fill>
                  </Rectangle>
                  <ContentPresenter />
              </Grid>
          </ControlTemplate>
      </Window.Template>
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups