你不能簡單地給Pane
的直接孩子塗上陰影,因爲它會被截斷。當然,你可以嘗試重寫SplitView
的風格和應用的影子直接到Pane
元素,但你很快就會發現,在PaneRoot
都有自己剪輯在XAML定義邏輯,所以如果你不小心,你可能會破壞其底層的UI邏輯。
這是一個簡單的解決方案,不需要修改樣式。這個想法是將陰影應用在內部元素上,在這個元素和Pane
的根元素之間有足夠的空間來擴散陰影。
假定PanePlacement
設置爲Right
,那麼你的根元素,一個Border
(即RootBorder
),應該有一個左填充(即12,0,0,0
)該DropShadowPanel
的匹配BlurRadius
(即12
)。
另外,PaneBackground
需要透明否則它會掩蓋影子。相反,背景顏色應該應用於根元素內的容器元素(即PaneContentGrid
)。
請參閱下面一個簡單的例子代碼 -
XAML
<SplitView PanePlacement="Right" PaneBackground="Transparent">
<SplitView.Pane>
<Border x:Name="RootBorder" Padding="12,0,0,0">
<Grid>
<controls:DropShadowPanel BlurRadius="12"
Color="Black"
Opacity="0.3"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<Rectangle Fill="White" />
</controls:DropShadowPanel>
<!-- SystemControlPageBackgroundChromeLowBrush is the default PaneBackground brush, feel free to change it to whatever you like! -->
<Grid x:Name="PaneContentGrid" Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}">
<!-- place your Panel content here. -->
</Grid>
</Grid>
</Border>
</SplitView.Pane>
</SplitView>
演示
貌似已經問問題或這個HTTPS的複製: //stackoverflow.com/questions/43395093/how-to-add-a-drop-s hadow-for-splitview-pane –
[如何爲SplitView.Pane添加投影]可能的重複(https://stackoverflow.com/questions/43395093/how-to-add-a-drop-shadow-for- splitview-pane) –
你錯過了這個人問的問題,我會引用:_但是,陰影出現在窗格內,而我希望它在SplitView.Pane之外,將它包裹起來。我怎樣才能實現呢?謝謝!_ –