2014-06-18 63 views
2
<DoubleAnimation Storyboard.TargetName="mainGrid" Storyboard.TargetProperty="Grid.Width" Duration="00:00:00.5" From="40" To="100"/> 

x:網格的名稱是mainGrid。如您所見,這是負責動畫的代碼。我想是這樣From="mainGrid.ActualWidth「和To="mainGrid.ActualWidth + 10"但我怎麼能結合這些值來ActualWidth的財產如何綁定屬性動畫值?

回答

0

您可以使用一個轉換器做考慮下面的標記示例:?

<Grid Name="mainGrid" Width="40" xmlns:local="clr-namespace:local"> 
    <Grid.Resources> 
     <local:Plus10Converter x:Key="Plus10Converter"/>  
    </Grid.Resources> 
    <Button> 
     <Button.Triggers> 
      <EventTrigger RoutedEvent="Button.Click"> 
       <EventTrigger.Actions> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetName="mainGrid" Storyboard.TargetProperty="Width" Duration="00:00:00.5" 
              From="{Binding ElementName=mainGrid, Path=ActualWidth}" 
              To="{Binding ElementName=mainGrid, Path=ActualWidth, Converter={StaticResource Plus10Converter}}"/> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger.Actions> 
      </EventTrigger> 
     </Button.Triggers> 
    </Button> 
</Grid> 

,這是後面的代碼:

namespace local 
{ 
    public class Plus10Converter : IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      if (value is double == false) return null; 
      return (double)value + 10.0; 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      throw new NotImplementedException(); 
     } 
    } 
} 
+0

我會盡快給它一個嘗試,並給你一個反饋。謝謝 – user258620