yapar: Bu kod, bir liste kutusunda görüntüler bir dizi görüntülemek için tasarlanmıştırWPF: Storyboard.TargetName çalışır, ancak Setter HedefAdı en böyle bir XAML kod var diyelim değil
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border HorizontalAlignment="Center" VerticalAlignment="Center">
<Border.LayoutTransform>
<!--We are rotating randomly each image. Selected one will be rotated to 45°.-->
<RotateTransform Angle="{Binding RandomAngle}" x:Name="globalRotation"/>
</Border.LayoutTransform>
<Grid>
<Image Source="{Binding ImageLocation}" Stretch="None" />
<TextBlock x:Name="title" Text="{Binding Title}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="title" Property="Visibility" Value="Visible"/>
<!--The next line will not compile.-->
<Setter TargetName="globalRotation" Property="Angle" Value="45"/>
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<!--This compiles well.-->
<DoubleAnimation Storyboard.TargetName="globalRotation" Storyboard.TargetProperty="Angle" To="45" Duration="00:00:03"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
. Her görüntü rasgele bir rotasyona sahiptir, ancak seçildiğinde 45 dereceye döner.
Seçili görüntüyü bir storyboard aracılığıyla döndürmek iyi çalışıyor. Sadece Storyboard.TargetName
belirtiyorum ve seçildiğinde görüntüyü döndürür (kodu daha kısa yapmak için Trigger.ExitActions
atlanır). Şimdi
, ben istersem yerine Bir film şeridi kullanmak yerine, ben <Setter TargetName="globalRotation" Property="Angle" Value="45"/>
çünkü bunu yapamaz, doğrudan 45 derece değeri atamak: Bu
ile derler "Tetik hedef 'globalRotation' bulunamıyor. (Hedef, onu kullanan herhangi bir Ayarlayıcı, Tetikleyici veya Koşullardan önce görünmelidir.) "
hatası. Ne oluyor? Çalışma zamanında Storyboard.TargetName
'un değerlendirildiğini varsayalım, bu yüzden derlememi sağlayın. Doğru mu?
Film şeridini kullanmadan nasıl bir ayarlayıcı ile çalışır?