您可以使用一個轉換器做考慮下面的標記示例:?
<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();
}
}
}
我會盡快給它一個嘗試,並給你一個反饋。謝謝 – user258620