2013-03-09 327 views
0

我有一個StackPanel陰影樣式。內容綁定到ObservableCollection並且每個項目都呈現爲圖像。當我從集合中刪除最後一項時,即使圖像不再存在,陰影仍然存在。這隻發生在最後一個項目上。徘徊WPF陰影

發生了什麼事?我如何確保陰影也被刪除?

 <Style TargetType="StackPanel" x:Key="ShadowedStackPanel"> 
      <Setter Property="BitmapEffect"> 
       <Setter.Value> 
        <DropShadowBitmapEffect Color="Black" Direction="50" ShadowDepth="5" Opacity=".65" Softness="1"/> 
       </Setter.Value> 
      </Setter> 
     </Style> 


    <ItemsControl x:Name="TilesControl"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal" Style="{StaticResource ShadowedStackPanel}" /> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Image Source="{Binding Path=ImageSource}"/> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 

代碼隱藏基本上是:

public ObservableCollection<TileViewModel> Hand = new ObservableCollection<TileViewModel>(); 

TilesControl.ItemsSource = Hand; 

// populate the collection here 

var last = Hand.Last(); 

Hand.Remove(last); 

這留下了揮之不去的陰影效果的影響。

rendering error

如果我在集合中刪除任何其他較早的項目,它重繪一切正常。這隻會發生,如果我刪除最後一個項目。

如果我調整窗口大小,它會重新繪製並固定......但是無論什麼原因,如果我不這樣做,它會留下一片揮之不去的陰影。

我該如何強制重繪以使陰影消失?或者首先避免這個問題?

回答

0

你可以刪除

TilesControl.Items.Refresh(); 
+0

這奏效了,感謝後使用的代碼。我試圖讓控制本身刷新,並沒有工作,但調用.Items.Refresh()很好。 – 2013-03-09 21:29:22

+0

是的。但是,如果我使用Button控件來代替Image,TilesControl可以很好地運行而不會產生任何技巧我不知道其他方法來解決你的控制與圖像。 – 2013-03-09 21:34:02