我有一個ItemsControl,它包含一些嵌套的容器。我想在主ItemsControl的每個元素上添加一個陰影。但是它將它添加到主ItemsControl中的某些容器(創建陰影行)。我已將效果置於多個不同的級別,但結果不變。我從ItemsControl主項目的最外層容器開始往上走。DropShadowEffect應用於子元素 - Silverlight XAML
這裏就是我現在有放置的陰影效果:
<ItemsControl >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!-- I have tried adding the dropshadow effect within this stackpanel -->
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- Where I define the dropshadow -->
<ItemsControl.Effect>
<DropShadowEffect BlurRadius="0" ShadowDepth="1" Color="LightGray"/>
</ItemsControl.Effect>
<!-- End of dropshadow definition -->
<ItemsControl.ItemTemplate>
<DataTemplate>
<media:Step5Item />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
,這裏是爲Step5Item的定義,我添加文檔,其中陰影出現:(編輯)我刪除內容因爲那只是造型等等。
<!-- This is inserted by the above code's DataTemplate -->
<!-- I have tried adding a border here and giving it a dropshadow effect -->
<Grid >
<!-- I have tried inserting a dropshadow effect here -->
<TextBlock Grid.Row="0"/>
<Border BorderBrush="LightGray" BorderThickness="1" >
<!-- I have tried inserting a dropshadow effect here -->
<Grid>
<Border >
<!-- There is a shadow around this border/grid -->
<Grid Grid.Row="0" >
<TextBlock Grid.Column="0" />
<Button Grid.Column="2"/>
</Grid>
</Border>
<!--There is a shadow around each element in this ItemsControl-->
<ItemsControl Grid.Row="2" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,4" >
<Path Grid.Row="0">
<Path.Data>
<LineGeometry StartPoint="0,0" EndPoint="1500,0"/>
</Path.Data>
</Path>
<Grid Grid.Row="1">
<Image Grid.Column="0" />
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Border>
</Grid>
也有在底部的影子,但我不知道它從ItemsControl中,如果最後一個元素是從最外層的邊界。
如果你想我可以清理更多的第二個代碼塊。我拿出了一些東西,但留在元素中,認爲這可能是最好的可讀性。
編輯 我嘗試應用效果後,我添加子元素希望,因爲他們之前的效果進入遊戲創建,不會出現問題。我嘗試將效果放在主ItemsControl的底部以及Step5Item中最外面的網格的底部。我也從Step5Item中刪除了一些內容,希望它更具可讀性。
EDIT2
這裏有兩個圖像具有和不具有效果。我把DropShadow代碼放在我放置在上面的位置,雖然就像我說的,我可以將它放在很多地方以獲得相同的效果。
有了陰影效果
With Error http://img811.imageshack.us/img811/2168/dropshadowerror.png
沒有陰影效果
Without Error http://img402.imageshack.us/img402/1456/nodropshadowexample.png
編輯3
這是邊境落,我從艾爾諾的解決方案使用的陰影效果。我希望能夠更多地增加陰影深度,因爲右側沒有任何陰影,只有底部。目前,如果我改變ShadowDepth它改變的陰影的位置是在一個距離等於新的大小,但它僅僅是一個厚度爲1
<Border Margin="0,1,0,0" Height="auto" Width="auto" CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="LightGray">
<Border.Effect>
<DropShadowEffect BlurRadius="0" ShadowDepth="1" Direction="315" Color="LightGray"/>
</Border.Effect>
</Border>
你可以張貼一些屏幕截圖來澄清問題嗎? – XAMeLi
@XAMeLi添加圖片 – StephenT
我還不明白這個問題。你能減少代碼嗎? –