2015-07-13 76 views
0

Whay我給出該錯誤''ScaleTransform'名稱無法在'System.Windows.Controls.ListView'的名稱範圍中找到」「。當ScaleTransform在另一個觸發器中,但是當我在Image.Triggers中設置它工作正常嗎?在'System.Windows.Controls.ListView'的名稱範圍中找不到'ScaleTransform'名稱

 <ListView.ItemTemplate> 
          <DataTemplate> 
           <DockPanel> 
            <TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/> 
            <Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True"> 
             <Image.RenderTransform> 
              <ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" /> 
             </Image.RenderTransform> 
            </Image> 
           </DockPanel> 
          </DataTemplate> 
         </ListView.ItemTemplate> 
         <ListView.Triggers> 
          <EventTrigger RoutedEvent="ListView.SelectionChanged"> 
           <BeginStoryboard Name="myBeginStoryboard"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" /> 
             <DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/> 
            </Storyboard> 
           </BeginStoryboard> 
          </EventTrigger> 
         </ListView.Triggers> 
        </ListView> 

,我嘗試也沒有工作:

<ListView.ItemTemplate> 
          <DataTemplate> 
           <DockPanel> 
            <TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/> 
            <Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True"> 
             <Image.RenderTransform> 
              <ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" /> 
             </Image.RenderTransform> 
            </Image> 
           </DockPanel> 
          </DataTemplate> 
         </ListView.ItemTemplate> 
         <ListView.Triggers> 
          <EventTrigger RoutedEvent="ListView.SelectionChanged"> 
           <BeginStoryboard Name="myBeginStoryboard"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.Target="{Binding MyAnimatedScaleTransform}" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" /> 
             <DoubleAnimation Storyboard.Target="{Binding MyAnimatedScaleTransform}" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/> 
            </Storyboard> 
           </BeginStoryboard> 
          </EventTrigger> 
         </ListView.Triggers> 
        </ListView> 

回答

0

我發現,在DataTemplate中的控制器無法訪問,所以我改變我的鱈魚的XAML到:

<ListView.ItemTemplate> 
         <DataTemplate> 
          <DockPanel> 
           <TextBlock DockPanel.Dock="Bottom" Text="{Binding Name}"/> 
           <Image x:Name="Img" Source="{Binding Source}" Height="128" Width="128" Focusable="True"> 
            <Image.RenderTransform> 
             <ScaleTransform x:Name="MyAnimatedScaleTransform" CenterX="25" CenterY="25" ScaleX="1" ScaleY="1" /> 
            </Image.RenderTransform> 
            <Image.Triggers> 
             <EventTrigger RoutedEvent="Image.MouseDown"> 
              <BeginStoryboard Name="myBeginStoryboard"> 
               <Storyboard> 
                <DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.25" AutoReverse="True" /> 
                <DoubleAnimation Storyboard.TargetName="MyAnimatedScaleTransform" Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.25" AutoReverse="True"/> 
               </Storyboard> 
              </BeginStoryboard> 
             </EventTrigger> 
            </Image.Triggers> 
           </Image> 
          </DockPanel> 
         </DataTemplate> 
        </ListView.ItemTemplate> 

現在我已經返回到我的主要問題,當我第一次動畫結束(逆向)之前第二次點擊圖像時,圖像不會恢復到原始大小。

+0

應該解決您的問題 –