murmansk murmansk - 25 days ago 162
C# Question

SystemParameter in MSDN example

I am trying to create a window Chrome with button, but I am not able to get title text and image, there is an example of MSDN for this but it has some keyword not working in VS2015

<Style x:Key="StandardStyle" TargetType="{x:Type local:MainWindow}">
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MainWindow}">
<Grid>
<Border Background="White"
Margin="{Binding Source={x:Static **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=(WindowChrome.WindowChrome).ResizeBorderThickness}"
Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>




what is "SystemParameters2.Current" in this example? Is it some system parameter or user defined?
Example by MSDN

mm8 mm8
Answer Source

In VS2015 / .NET Framework 4.5 there is a SystemParameters class available in the PresentationFramework assembly that contains the WindowNonClientFrameThickness and SmallIconWidth properties so the equivalent would be:

<Grid>
    <Border Background="White"
                    Margin="{Binding Source={x:Static SystemParameters.WindowNonClientFrameThickness}}">
        <ContentPresenter Content="{TemplateBinding Content}" />
    </Border>
    <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                           VerticalAlignment="Top" HorizontalAlignment="Left" 
                           Margin="36,8,0,0"/>
    <Image ...
                       Width="{Binding Source={x:Static SystemParameters.SmallIconWidth}"
                       WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>