Non Rectangular Window in WPF Help
-
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.
-
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.
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>