Search code examples
c#wpfhiddenexpression-blend

WPF ignores d:IsHidden="True" in run mode (OK in design mode)


Why is the left image hidden in Design Mode and NOT hidden in Runtime? It looks like WPF ignores the attribute "IsHidden". New empty solution, no single line of code - just Blend.

Left is Design Mode - Right is in Run Mode

Here is my code

<Window
    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" mc:Ignorable="d" x:Class="WpfApplication222.MainWindow"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Image HorizontalAlignment="Left" Height="157.093" Margin="98.316,88.148,0,0" VerticalAlignment="Top" Width="95" Source="pack://siteoforigin:,,,/img0.jpg" RenderTransformOrigin="0.5,0.5" d:IsHidden="True">
        <Image.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="-37.445"/>
                <TranslateTransform/>
            </TransformGroup>
        </Image.RenderTransform>
    </Image>
    <Image HorizontalAlignment="Left" Height="122" Margin="350,92,0,0" VerticalAlignment="Top" Width="106" RenderTransformOrigin="0.5,0.5" Source="pack://siteoforigin:,,,/img14.jpg">
        <Image.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="13.144"/>
                <TranslateTransform/>
            </TransformGroup>
        </Image.RenderTransform>
    </Image>
</Grid>


Solution

  • At the top of your XAML, you'll see the following:

    mc:Ignorable="d" 
    

    This basically says "Ignore anything prefixed with d: at runtime."

    You can either remove this line (not recommended), or use the Visibility property instead. Which will not be ignored.