別のプロジェクトで直面している奇妙さを実証することを目的とした単純な WPF (4.0) サンプルがあります。このサンプルでは、Border 要素を使用するいくつかの四角形を表示しようとしています。以下はマークアップです。
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window3" Height="1000" Width="1500">
<Window.Resources>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="grad">
<LinearGradientBrush.GradientStops>
<GradientStop Color="Black" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style TargetType="Border">
<Setter Property="Background" Value="{StaticResource grad}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="100" />
<Setter Property="BorderThickness" Value="1" />
</Style>
</Window.Resources>
<StackPanel Orientation="Horizontal">
<Border />
<Border />
<Border />
</StackPanel>
</Window>
デザイナーでは、これはまさに私が想像しているとおりに見えます。画面の左上に 3 つの正方形が隣り合っています。ただし、実行時には 1 つだけが表示され、残りのウィンドウは黒くなります。ウィンドウのコンテンツ自体は、レイアウト プロパティの影響を受けているようです。Borders の代わりに Rectangles を使用すると、サンプルは問題なく動作します。この動作が見られる理由を誰か説明してもらえますか (継承に関連している可能性があります)。また、デザイン時ビューと実行時ビューの違いは基本的に VS のバグですか?