MSDN Example Not Working

Martin Bornhøft 1 Reputation point
2021-09-17T13:45:05.987+00:00

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?

XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 38,251 Reputation points Microsoft Vendor
    2021-09-21T02:46:36.47+00:00

    Thank you for taking time to post this issue in Microsoft Q&A forum.
    Visual Studio Code is different from Visual Studio and it is currently not supported in the Microsoft Q&A forums, the supported products are listed over here: https://learn.microsoft.com/en-us/answers/products/ (more to be added later on).
    For the related questions about Visual Studio Code, you can post here: GitHub-vscode.


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    0 comments No comments