2010-03-12 137 views
0

動畫依賴屬性我想出去,以得到它是如何工作掛起動畫依賴項屬性的一個例子。 所有它應該做的就是改變列的寬度,但由於某些原因,我的斷點沒有被擊中,顯然沒有任何反應。在Silverlight

的代碼是:

<UserControl x:Class="SilverlightApplication1.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" x:Name="Myself"> 
    <UserControl.Resources> 
     <Storyboard x:Name="Storyboard1"> 
      <DoubleAnimation Storyboard.TargetName="Myself" Storyboard.TargetProperty="ColumnWidth" To="0" Duration="00:00:05"/> 
     </Storyboard> 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot"> 
     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Grid Background="Black"> 
      <Grid.RenderTransform> 
       <TransformGroup> 
        <ScaleTransform /> 
        <SkewTransform /> 
        <RotateTransform /> 
        <TranslateTransform /> 
       </TransformGroup> 
      </Grid.RenderTransform> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition x:Name="Column1" 
            Width="140" /> 
       <ColumnDefinition Width="250" /> 
       <ColumnDefinition Width="250" /> 
      </Grid.ColumnDefinitions> 
      <Rectangle Fill="White" Stroke="Black" Margin="5"/> 
      <Rectangle Fill="White" Stroke="Black" Margin="5" Grid.Column="1"/> 
      <Rectangle Fill="White" Stroke="Black" Margin="5" Grid.Column="2"/> 
     </Grid> 

     <StackPanel Grid.Row="1"> 
       <Button x:Name="button1" Content="Change column width" 
       Click="button1_Click" Height="100"/> 
     </StackPanel> 

    </Grid> 

</UserControl> 

和後面的代碼:

namespace SilverlightApplication1 
{ 
    public partial class MainPage : UserControl 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      Storyboard1.Begin(); 
     } 

     public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", 
                            typeof (double), 
                            typeof (MainPage), 
                            new PropertyMetadata 
                             (ColumnWidthChanged)); 
     public double ColumnWidth 
     { 
      get 
      { 
       return (double)GetValue(ColumnWidthProperty); 
      } 
      set 
      { 
       SetValue(ColumnWidthProperty, value); 
      } 
     } 

     private static void ColumnWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
     { 
      var mainPage = (MainPage) d; 
      mainPage.Column1.Width = new GridLength((double)e.NewValue); 
     } 
    } 
} 

JD。

+0

請花幾分鐘時間來閱讀常見問題解答和降價文件(一個有用的synposis它的編輯問題時,右邊是可用)。 – AnthonyWJones 2010-03-12 16:31:06

+0

對不起安東尼,我忘記縮進代碼了嗎?我保存它看起來很好。 – 2010-03-12 16:39:20

回答

1

你的動畫從0到0值這就是爲什麼不被稱爲你ColumnWidthChanged方法,因爲它並沒有改變。

+0

謝謝格雷姆,今天早上我注意到它,並希望回答我自己的問題。 – 2010-03-17 12:29:58