2017-05-11 32 views
0

我想將我的按鈕始終放在ScrollViewer的底部框架中間。我將改變窗口的大小和ScrollViewer的大小,但我希望我的按鈕始終與圖片一樣。WPF按鈕位置依賴於另一個元素

enter image description here 由於我關注MVVM,我只是xaml。基本上,我想綁定(生活)按鈕頂部的位置從模式:

button.top = (scrollViewer.top + scrollViewer.height) - button.height/2 

我將不勝感激您的建議。

[編輯]我忘了補充說,所有其他控件在網格行和列。

+0

在代碼隱藏中設置button.top不會以任何方式破壞MVVM。 –

+0

它是否總是相同'ScrollViewer' - 你的'Button'被放置在哪裏? – Peter

回答

2

您可以嘗試使用Grid來實現這一點。如果您需要更改ScrollViewer尺寸,則只需更改ScrollGrid網格尺寸。要重疊底部或頂部內容,可以使用按鈕的負邊距。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="100"/> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="100"/> 
    </Grid.RowDefinitions> 
    <Border Background="Red"/> 
    <Border Background="Red" Grid.Row="2"/> 
    <Grid x:Name="ScrollGrid" Grid.Row="1"> 
     <ScrollViewer></ScrollViewer> 
     <Button Width="100" Height="100" VerticalAlignment="Bottom" HorizontalAlignment="Center"/> 
    </Grid> 
</Grid> 
+0

謝謝。這比我想象的要簡單得多。它也可以與Storyboard一起使用。 – Niko