How to get Drop Shadow Effect on Metrowindow WPF - c#

I am using a Metrowindow as my main Window.xaml for my application. However, after trying different results from Google I still can't manage to get my window to drop a shadow effect.
My Code:
Window.xaml
<Metro:MetroWindow x:Class="ROGERS.Windows.Window"
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:ROGERS.Windows"
xmlns:ViewModels="clr-namespace:ROGERS.Windows.ViewModels"
xmlns:Views="clr-namespace:ROGERS.Windows.Views"
xmlns:Metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:MetroIcons="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
TitleAlignment="Center"
TitlebarHeight="26"
Height="800"
Width="1440"
ShowIconOnTitleBar="False"
WindowStartupLocation="CenterScreen"
WindowTitleBrush= "#0c3868"
BorderBrush="#0c3868"
WindowStyle="None"
BorderThickness="1"
AllowsTransparency="False"
Closing="MetroWindow_Closing">
<Metro:MetroWindow.Effect>
<DropShadowEffect Color="Black" BlurRadius="20" Direction="90" RenderingBias="Quality" ShadowDepth="3"/>
</Metro:MetroWindow.Effect>
<Metro:MetroWindow.DataContext>
<ViewModels:WindowViewModel />
</Metro:MetroWindow.DataContext>
<Frame Source="Views/ReportGenerator.xaml" x:Name="ReportGeneratorFrame" />
</Metro:MetroWindow>
Anyone knows how to get the effect?

The docs for MetroWindow explain how to do it using the GlowBrush property.
https://mahapps.com/docs/controls/metrowindow

Related

Adding shadow to WPF form with BorderThickness = 0

I have a WPF borderless window with a shadow set to the grid shown below:
<Window x:Class="Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" WindowStyle="None"
AllowsTransparency="True" Background="Transparent" BorderThickness="0">
<Grid>
<Grid.Effect>
<DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
</Grid>
</Window>
However, when the BorderThickness is set to 0, the shadow doesn't appear. When I increase this, the shadow will appear, but when the window is moved to the edge of the screen using DragMove(), a gap is left (presumably the width of BorderThickness).
How can I, therefore, add a shadow around the window with BorderThickness set to 0? Thanks in advance.
<Window x:Class="WpfApp7.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:WpfApp7"
mc:Ignorable="d" WindowStyle="None"
AllowsTransparency="True" Background="Transparent" BorderThickness="0"
Title="MainWindow" Height="450" Width="800">
<Grid Margin="10">
<Grid.Background>
<SolidColorBrush Color="Green" Opacity="1"/>
</Grid.Background>
<Grid.Effect>
<DropShadowEffect Color="Black" BlurRadius="15" Direction="-90"
RenderingBias="Quality" ShadowDepth="2"/>
</Grid.Effect>
</Grid>
:) just add margin to the grid. It needs space to show the shadow.

How to remove border when WindowStyle="None" AllowsTransparency=“False” and ResizeMode="CanResize"

I have a window with the following properties
WindowState="Maximized"
WindowStyle="None,
AllowsTransparency="False"
ResizeMode="CanResize"
But the problem is a border appears around the window.
How can I fix it without changing any of these properties
When I set AllowsTransparency True some user controls such as PdfViewer,WebBrowser not displaying contents.
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
WindowState="Maximized"
AllowsTransparency="False"
ResizeMode="CanResize"
UseLayoutRounding="True"
Title="MainWindow">
<Grid Background="Red"></Grid>
</Window>
You could use a WindowChrome:
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
AllowsTransparency="False"
ResizeMode="CanResize"
UseLayoutRounding="True"
Title="MainWindow">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="0" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid Background="Red"></Grid>
</Window>

WPF window with WindowChrome resizing issue

Have this simple XAML for a custom window. It works fine except during a resize (from the left, top, top-left and bottom-left) it looks awful. The window flashes like crazy. Doesn't seem like an OS issue as Microsoft's glass Windows app resize smooth as butter.
I'm trying to customize the window frame, but unless I use WindowChrome, I lose all the resizing, dragging, etc.
<Window x:Class="WpfApp2.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:WpfApp2"
WindowStyle="None"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="450" Width="600">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="1,1,1,1" />
</WindowChrome.WindowChrome>
<Border BorderBrush="Red" BorderThickness="1">
<Button Content="Test" Height="25" Width="75" />
</Border>
</Window>

Zoombox from Xceed WPF Toolkit not working

I am experimenting with the Zoombox control from Xceed, but I am having trouble getting it to respond to mouse wheel or pan events. Nothing happens when I use these inputs. Am I missing something in my code or configuration?
https://github.com/xceedsoftware/wpftoolkit
<Window x:Class="UI.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:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="700">
<Grid>
<xctk:Zoombox MinScale="0.5" MaxScale="100" >
<Grid Width="600" Height="400" Background="Yellow">
<Ellipse Fill="Blue" />
</Grid>
</xctk:Zoombox>
</Grid>
</Window>
You have to define DragModifiers and ZoomModifiers. Default values are Ctrl and Shift keys. So use the combination Shift+MouseWheel for zooming and use Ctrl+LeftButton for panning.

WPF page content not setting to window's size

I made a WPF application in which. I placed a rectangle. The page is covering whole window but the size(width) of rectangle is not equal to the page.
here is the pic.
here is the source code of my application:
<Page x:Class="TestWpfApplication.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestWpfApplication"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525"
Title="Page1" Background="#FF7ACBBC" ShowsNavigationUI="False">
<Grid>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="525"/>
<Label x:Name="label" Content="Heading" HorizontalAlignment="Left" Margin="222.006,25,0,0" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="22"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="160,155,0,0" TextWrapping="Wrap" Text="And rest of the content goes here" VerticalAlignment="Top" FontFamily="Tahoma" FontSize="14"/>
</Grid>
And
<Window x:Class="TestWpfApplication.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:TestWpfApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:Page1/>
</Grid>
At last App.xaml
<Application x:Class="TestWpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfApplication"
StartupUri="page1.xaml">
<Application.Resources>
</Application.Resources>
Please help me....
Set SizeToContent Property of Window to SizeToContent="WidthAndHeight"
SizeToContent
Page1.Xaml.cs:
public Page1()
{
InitializeComponent();
this.SizeToContent = SizeToContent.WidthAndHeight;
}
For more Info, See Window.SizeToContent Property
I don't know why you specified size parameters for rectangle and expect it to fit your page's size. Just remove all these parameters and it will stretch.
<Rectangle Fill="#FFF4F4F5"/>

Categories

Resources