Hello MSDN
I'm using Visual Studio CODE (not the full-blown Visual Studio) in .NET5.0. I can't get the following example to work
https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.windowchrome?view=net-5.0
My project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows7.0</TargetFramework>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="-SomeProject-.csproj" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
</ItemGroup>
</Project>
and the MainWindow.xaml looks like this:
<Window x:Class="FileSystemExplorer.Frontend.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:shell="clr-namespace:System.Windows.Shell"
mc:Ignorable="d"
Title="MyWindow"
WindowStyle="None"
ResizeMode="CanResize"
AllowsTransparency="True"
Background="Red">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome ResizeBorderThickness="5" GlassFrameThickness="-1" CornerRadius="0" CaptionHeight="25" />
</shell:WindowChrome.WindowChrome>
<Window.Resources>
<Style TargetType="{x:Type local:MainWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MainWindow}">
<Grid>
<Border Background="White"
Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}">
<ContentPresenter Content="{TemplateBinding Content}" />
</Border>
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="36,8,0,0"/>
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
VerticalAlignment="Top" HorizontalAlignment="Left"
Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}"
Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
shell:WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Window.Effect>
<DropShadowEffect Color="Gray" BlurRadius="20" Direction="-90" RenderingBias="Quality" ShadowDepth="4"/>
</Window.Effect>
</Window>
I am getting
error MC3074: The tag 'WindowChrome.WindowChrome' does not exist in XML namespace 'clr-namespace:System.Windows.Shell'
If I call WindowChrome.SetWindowChrome(this, new WindowChrome { ... });
in MainWindow.xaml.cs (aka. code behind) with using System.Windows.Shell;
it works, but not if XAML.
Can you tell me what I'm missing?