現在、コードを作成する必要なく、コントロールを WPF のボックス形状に表示するのに苦労しています。これが私がそれをどのように見せたいかの実際の例です:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="3" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Margin="6" VerticalAlignment="Stretch" Width="{Binding Path=ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Source="http://blog.joeclarmusic.com/images/rss-icon.jpg" />
<TextBlock Foreground="Black" TextAlignment="Center" Grid.Row="1" FontSize="11" Text="{Binding Path=Name}" Margin="0, 5, 0, 0" HorizontalAlignment="Center" TextWrapping="Wrap" />
</Grid>
</Button>
</StackPanel>
<GridSplitter Grid.Row="1" Background="#DDDDDD" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>
わかりました、これはすべてクールでうまくいきます。私の現在のデザインでは、ItemsControl を使用して画像のリストを表示しています。このようなリストはウィンドウの幅を超える可能性があるため、VerticalScrollBar が無効になっている StackPanel の周りに ScrollViewer を追加したいと考えました (左から右にのみ流れるようにしたいので、HorizontalScrollBar のみが必要です)。
ScrollViewer を追加した後:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="3" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer>
<StackPanel Orientation="Horizontal">
<Button Margin="6" VerticalAlignment="Stretch" Width="{Binding Path=ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image Source="http://blog.joeclarmusic.com/images/rss-icon.jpg" />
<TextBlock Foreground="Black" TextAlignment="Center" Grid.Row="1" FontSize="11" Text="{Binding Path=Name}" Margin="0, 5, 0, 0" HorizontalAlignment="Center" TextWrapping="Wrap" />
</Grid>
</Button>
</StackPanel>
</ScrollViewer>
<GridSplitter Grid.Row="1" Background="#DDDDDD" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>
私のコンピューターで kaxaml 1.7.1 を実行したときの上記の画像: jonatan.nilsson.is/wpf_with_scrollviewer.jpg
Kaxaml (または WPF ウィンドウ/ページ) で実行すると、ボタンはどんどん大きくなります (幅と高さの両方)。私が行った唯一の変更は、StackPanel の周りに ScrollViewer を追加することです。他のすべては同じですが、スクロールビューア内で大きくなり続けるのはなぜですか?
ここで何が間違っていますか?
編集: 2 番目の例の結果の画像を追加しました。