question

MartinBornhft-5385 avatar image
0 Votes"
MartinBornhft-5385 asked HuiLiu-MSFT answered

MSDN Example Not Working

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://docs.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?






dotnet-wpf-xaml
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered

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://docs.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 to enable e-mail notifications if you want to receive the related email notification for this thread. 

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.