WPF window corner radius and shadow - wpf

I want to have a window without buttons, with rounded corners and with shadow.
Like this:
So this is my XAML code:
<Window x:Class="Password.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Password"
mc:Ignorable="d"
Title="MainWindow" Height="294" Width="546" Background="Transparent" Foreground="#FFE755DD" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Grid >
<Grid.Effect>
<DropShadowEffect BlurRadius="20" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
<Border Background="#FF22173C" CornerRadius="20, 20, 20, 20"/>
</Grid>
</Window>
And this is the output:
The shadow isn't rounded.
What should I do?

The blur gets cropped because your window doesn't own the space around it.
Set <Grid Margin="20"> to allow the blur to occur in the area you control.

Related

Bing maps WPF add location markers

I have a pushpin on my map, but when I click and drag the map the pushpin stays on the same spot on the screen and doesn't move with the map. How do I put the pushpin on a specific location (coordinates) and have it stay there?
Here is my XAML code:
<Window x:Class="WPFKiosk.MapWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFKiosk"
mc:Ignorable="d"
Title="MapWindow" Height="910" Width="1080" WindowStyle="None" ResizeMode="NoResize">
<!-- -->
<Grid Width="1080" Height="915">
<!-- <Image HorizontalAlignment="Left" Height="644" Margin="20,64,-35,0" VerticalAlignment="Top" Width="1095" Source="Images/map.png"/> -->
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road"/>
<m:Pushpin Location="28,-81"
/>
<Image HorizontalAlignment="Left" Height="100" Margin="510,740,0,0" VerticalAlignment="Top" Width="100" Source="Images/iTO Back Arrow.png" MouseLeftButtonDown="Image_MouseLeftButtonDown"/>
</Grid>
</Window>
The Pushpin is not "on the map".
It should look like this:
<m:Map x:Name="myMap" CredentialsProvider="My_Key" Mode="Road">
<m:Pushpin Location="28,-81"/>
</m:Map>

WPF Window Not Showing Transparency Correctly

TI'm having some trouble getting my Window to be Transparent.
The Window is defined below:
<Window x:Class="HKC.Desktop.Views.UserInterfaces.RemoteKeypad"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Closing="Window_Close"
KeyDown="RemoteKeypad_KeyDown"
KeyUp="RemoteKeypad_KeyUp" MouseDown="OnMouseDown_Event"
Title="Title" Width="325" Height="370"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
I then have a border defined to give a curved edge to the Window, with a Grid inside for layout purposes:
<Border CornerRadius="20" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Border.Effect>
<DropShadowEffect BlurRadius="6" ShadowDepth="3" Color="#484948" />
</Border.Effect>
<Grid Background="Transparent" VerticalAlignment="Stretch">
....
</Grid>
</Border>
</Window>
For some reason, the first time that I open the window the background is not transparent
However, If I click away from the Window, back back on it, the transparency is working as expected.
Turns out the problem was with an external tool for adding Drop Shadows to elements.

initial size of element wpf

I have window with this markup
<Window x:Class="TestCloseWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Button Command="ApplicationCommands.Close">Foo</Button>
</Window>
I'd like to button have MinWidth and MinHeight 100
and MaxHeight and MinHeight equals to 500
And like size window to content so I make this
<Window x:Class="TestCloseWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight" >
<Button MaxHeight="500" MaxWidth="500" MinHeight="100" MinWidth="100" Command="ApplicationCommands.Close">Foo</Button>
</Window>
And I'd like to set initial size of button 200 x 200
without writing Width and Height in window
If I write Width="200" Height="200" in button, button becomes unresizable.
How can I set initial size of control?
I am not sure exactly what you are trying to accomplish, but see if this does what you are wanting. I am using a ViewBox to stretch the Contents when the Window is resized, and setting the contraints in the Window. Be aware that Window Size is different than Window Client Area size.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" MaxHeight="500" MaxWidth="500"
MinWidth="100" MinHeight="100"
Width="200" Height="200">
<Viewbox StretchDirection="Both" Stretch="Fill">
<Button >Hello</Button>
</Viewbox>

WPF: Drop shadow on borderless window without custom chrome

Im struggling with drop shadow on WPF-windows with WindowStyle=None and ResizeMode=NoResize. Is there any good alternative to using a DropShadow-effect on the window-content? I have tried WindowChrome in Shell Integration Library but its not showing any "Chrome" when ResizeMode=NoResize.
If it was possible somehow to draw a wpf-drop-shadow outside my window borders it could be a solution. If Im drawing the drop shadow inside the window I get a different behaviour then standard when for instance moving the mouse-cursor over the shadow. There should be no hit testing in my window when doing this and clicking this area should activate the window behind etc.
Zune seem to be drawing its own drop shadow because its not looking exactly like the standard Chrome-shadow. But its behaving like a normal drop shadow in that way its not capturing mouse events. I wonder how they do it.
Spotify also has another kind of shadow which is also not capturing mouse events.
I guess these apps draw their own WindowChrome completely, but how? Is this supported in WPF somehow?
<Window x:Class="ShellIntegrationTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
Title="MainWindow" Height="512" Width="384" WindowStyle="None" ResizeMode="NoResize">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome ResizeBorderThickness="5" GlassFrameThickness="-1" CornerRadius="0" CaptionHeight="25" />
</shell:WindowChrome.WindowChrome>
</Window>
This code will work on a borderless window to show the shadow if the window is set to not resize and it's style is none.
xmlns:local="clr-namespace:BorderTest"
mc:Ignorable="d" WindowStyle="None" ResizeMode="NoResize"
Title="MainWindow" Height="350" Width="525" AllowsTransparency="True" Background="Transparent">
<Border Margin="10" BorderThickness="1" BorderBrush="Blue">
<Border.Effect>
<DropShadowEffect Color="Black"
Direction="270"
BlurRadius="10"
ShadowDepth="3" />
</Border.Effect>
<Grid Background="White">
</Grid>
</Border>
If you change ResizeMode to CanResize and set the ResizeBorderThickness to 0, you'll get a borderless window, which cannot be resized and the drop shadow can be clicked through so the window behind it activates.
<Window
.........
.........
.........
Title="Welcome" Loaded="Window_Loaded" Height="400" Width="400" ResizeMode="NoResize" AllowsTransparency="True" WindowStyle="None" ShowInTaskbar="False" WindowStartupLocation="CenterScreen" Background="Transparent" BorderThickness="0">
<Border Margin="10" CornerRadius="100"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="10">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid>
...
...//main design inside windows
...
</Grid>
</Border>

Is there any way we can Automatically Stretch Horizontally or Vertically Childrens in Canvas like Grid does?

Is there any way whether we can stretch Element placed inside a Convas if we give the Horizotal and Vertical Alignment properties to Stretch?
You could try something like this:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Canvas Name="theCanvas">
<Button Content="Hello" Width="{Binding ActualWidth, ElementName=theCanvas}" />
</Canvas>
</Window>

Resources