2017-03-13 4 views
1

を2つ含むGridがあります。最初のボタンを左に、もう1つを右に揃えたい(これが私がGridを親として使用している理由です)。ウィンドウ全体が押し込まれてボタンが完全に見えなくなると、私はそれらをラップします。最初のものは左に揃えたままにしますが、2番目のものは新しい行に移動します(そして、必ずしもそうである必要はありませんが、まだ右に揃っている必要はありません)。そのためにはWrapPanelを使用しますが、WrapPanelは親ウィンドウを満たさないため、ボタンを左右に揃えません。要素を水平方向に最大幅に整列させますが、親を絞ると折り返します

水平アライメントとラッピングの両方を行う方法はありますか?

私の現在のコード: - 水平方向の配置やラッピング

<Grid Grid.Row="2" Visibility="{Binding Attachments.Count, Converter={StaticResource GreaterThanGivenValueVisibilityConverter}, ConverterParameter=1}"> 
    <Button Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="30" BorderThickness="0" Focusable="False" Command="{Binding ExpandAttachmentsPanel}"> 
    </Button> 
    <Button Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Top" Height="30" BorderThickness="0" Focusable="False" Command="{Binding DownloadAllAttachmentsCommand}"> 
    </Button> 
</Grid> 
+0

はあなたには、いくつかのコピー/ pastableコードを追加していただけますか?グリッド環境(Grid.Row = "2" ') – lokusking

+0

Grid.Row =" 2 "は実際には無関係ですが、それはあなたの問題を想像することができます。それは単に親要素の行の配置に関係します – Val

答えて

2

は両方を取得する方法はありますか?

あなたにこの振る舞いを与えることPanelビルトインいますがWrapPanelSizeChangedイベントを処理し、プログラムでボタンのいずれかのMarginを調整することができるはずです何もありません。このような何か:

<WrapPanel x:Name="wp" Background="Yellow" SizeChanged="WrapPanel_SizeChanged"> 
    <Button x:Name="btn1" Width="100"> 
     <TextBlock>1</TextBlock> 
    </Button> 
    <Button x:Name="btn2" Width="100"> 
     <TextBlock>2</TextBlock> 
    </Button> 
</WrapPanel> 

private void WrapPanel_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    btn1.Margin = new Thickness(0, 0, Math.Max(0, wp.ActualWidth - btn1.ActualWidth - btn2.ActualWidth), 0); 
} 

enter image description here

関連する問題