ラップ パネル (または他のコントロール) がスクロールビューアーの幅の計算に参加しないようにする方法はありますか? 以下の例では、ラップ パネルを他のコントロールによって作成された幅内にとどめ、幅の計算に直接影響を与えないようにしたいと考えています。(つまり) 自動がオフの場合と同様の動作が必要ですが、他のコンテンツの水平スクロールを許可すると、幅が広がります。
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<WrapPanel Grid.Column="1" Name="ctlWrap" />
<TextBox Grid.Row="1" Grid.Column="1" Width="100" HorizontalAlignment="Left" Name="ctlText" />
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
<Button Click="Button_Click">Add Wrap</Button>
<Button Click="Button_Click_1">Remove Wrap</Button>
<Button Click="Button_Click_2">Add Text</Button>
<Button Click="Button_Click_3">Remove Text</Button>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
</Window>
ボタンに使用したコードは次のとおりです。
Class MainWindow
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
ctlWrap.Children.Add(New Button With {.Content = "Button " & ctlWrap.Children.Count + 1})
End Sub
Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
If ctlWrap.Children.Count Then
ctlWrap.Children.RemoveAt(ctlWrap.Children.Count - 1)
End If
End Sub
Private Sub Button_Click_2(sender As Object, e As RoutedEventArgs)
ctlText.Width += 30
End Sub
Private Sub Button_Click_3(sender As Object, e As RoutedEventArgs)
If ctlText.Width > 60 Then ctlText.Width -= 30
End Sub
End Class