DpiPrescaleThemedImageConverter Class

Visual Studio 2015
 

Converts an ImageSource into an Image element. If the input image is a BitmapSource, the transformed BitmapSource has its halo color mapped to the given background color and is conditionally rendered as disabled. The resultant image is then pre-scaled on High DPI to the largest zoom multiple of 100% smaller than the DPI zoom. This converter chains the behavior of ThemedImageConverter and DpiPrescaleImageSourceConverter.

Namespace:   Microsoft.VisualStudio.PlatformUI
Assembly:  Microsoft.VisualStudio.Shell.14.0 (in Microsoft.VisualStudio.Shell.14.0.dll)


public ref class DpiPrescaleThemedImageConverter : DpiPrescaleThemedImageConverter

NameDescription
System_CAPS_pubmethodDpiPrescaleThemedImageConverter()

Initializes a new instance of DpiPrescaleThemedImageConverter.

NameDescription
System_CAPS_protpropertyDpiHelper

Gets an instance of the DpiHelper.(Overrides DpiPrescaleThemedImageConverter::DpiHelper.)

/// A common usage pattern can look like this:/// /// Where the image dimensions aren't known at compile time, instead of specifying exact Width/Height properties, /// a layout transform can be specified on the FrameworkElement like this:/// /// Note that when using image pre-scaling, either the original image size has to be specified, /// or a reverse layout transform has to be applied to the result, to maintain the desired original image size

<imaging:DpiPrescaleThemedImageConverter x:Key="DpiPrescaleThemedImageConverter" />
....
<ControlTemplate x:Key="MyMenuItemTemplate" TargetType="{x:Type MenuItem}">
    <ContentPresenter x:Name="Icon" Width="16" Height="16" ContentSource="Icon" />
...
</ControlTemplate>   
<Style x:Key="MyMenuItemStyleKey" TargetType="{x:Type MenuItem}">
///        <Setter Property="Template" Value="{StaticResource MyMenuItemTemplate}" />
    <Setter Property="Icon">
        <Setter.Value>
            <MultiBinding Converter="{StaticResource DpiPrescaleThemedImageConverter}">
                <Binding Path="Image" />
                <Binding Path="(imaging:ImageThemingUtilities.ImageBackgroundColor)" RelativeSource="{RelativeSource Self}" />
                <Binding Source="{x:Static utilities:Boxes.BooleanTrue}" />
            </MultiBinding>
        </Setter.Value>
    </Setter>
</Style>

Where the image dimensions aren't known at compile time, instead of specifying exact Width/Height properties, a layout transform can be specified on the FrameworkElement like this:

<ContentPresenter.LayoutTransform>
    <ScaleTransform ScaleX="{x:Static util:DpiHelper.Default.PreScaledImageLayoutTransformScaleX}" ScaleY="{x:Static util:DpiHelper.Default.PreScaledImageLayoutTransformScaleY}" />
</ContentPresenter.LayoutTransform>

Note that when using image pre-scaling, either the original image size has to be specified, or a reverse layout transform has to be applied to the result, to maintain the desired original image size.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: