トップ回答者
隠しておいたコントロールを表示させたときにアニメーションさせるには

質問
-
お世話になっております。
標題を実現するために、下記のように書こうとしているのですが、"???"のところがわかりません。
必要に応じて表示/非表示を切り替えたいので、Loadedイベントではないですよね。
コードビハインドで書くしかないのでしょうか?
<TextBlock Name="uiTextBlock" Visibility="Collapsed"> <TextBlock.LayoutTransform> <RotateTransform x:Name="Rotate"/> </TextBlock.LayoutTransform> <TextBlock.Triggers> <EventTrigger RoutedEvent="???" SourceName="uiTextBlock"> <BeginStoryboard> <Storyboard RepeatBehavior="Forever"> <DoubleAnimation BeginTime="00:00:00" Duration="0:0:10" Storyboard.TargetName="Rotate" Storyboard.TargetProperty="Angle" From="0" To="360"> </DoubleAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </TextBlock.Triggers> </TextBlock>
教えてください。よろしくお願いします。
回答
-
<Trigger Property="IsVisible" Value="true">
これじゃまずいんですね。うーん勉強になった。IsVisible は、スタイル トリガとして使用するためのものではありません。IsVisible をスタイル トリガとして使用すると、予期しない結果が生じる可能性があります。IsVisible は、低レベルの入力実装による状態チェック用です。
http://msdn.microsoft.com/ja-jp/library/system.windows.uielement.isvisible(v=VS.80).aspxIsEnabled
を使ったらどうでしょうか?
えムナウ@わんくま同盟 Microsoft MVP Visual Studio C# Since 2005/01-2010/12- 回答としてマーク Yo48 2010年8月24日 9:36
すべての返信
-
<Trigger Property="IsVisible" Value="true">
これじゃまずいんですね。うーん勉強になった。IsVisible は、スタイル トリガとして使用するためのものではありません。IsVisible をスタイル トリガとして使用すると、予期しない結果が生じる可能性があります。IsVisible は、低レベルの入力実装による状態チェック用です。
http://msdn.microsoft.com/ja-jp/library/system.windows.uielement.isvisible(v=VS.80).aspxIsEnabled
を使ったらどうでしょうか?
えムナウ@わんくま同盟 Microsoft MVP Visual Studio C# Since 2005/01-2010/12- 回答としてマーク Yo48 2010年8月24日 9:36
-
えムナウ様
IsEnabledで実現できました。ありがとうございました。
XAML+C#のコードをアップしておきます。
<!-- XAML -->
<Window.Resources> <Style x:Key="LabelStyleRotate" TargetType="{x:Type Label}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Label}"> <Border SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"> <ContentPresenter.LayoutTransform> <RotateTransform x:Name="Rotate"/> </ContentPresenter.LayoutTransform> </ContentPresenter> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="true"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard RepeatBehavior="Forever"> <DoubleAnimation BeginTime="00:00:00" Duration="0:0:10" Storyboard.TargetName="Rotate" Storyboard.TargetProperty="Angle" From="0" To="360"> </DoubleAnimation> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid x:Name="LayoutRoot"> <StackPanel> <Button Margin="5" Width="80" Click="OnShowButtonClicked">Show</Button> <Grid Margin="5" Width="300" Height="300"> <Label Name="uiLabel" Content="ABC" IsEnabled="False" Visibility="Hidden" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{DynamicResource LabelStyleRotate}" FontSize="96"/> </Grid> </StackPanel> </Grid>
//C#
public partial class MainWindow : Window { private void OnShowButtonClicked(object sender, RoutedEventArgs e) { uiLabel.Visibility= Visibility.Visible; uiLabel.IsEnabled= true; } }
Label のTemplateの書き方がわからず、はじめてBlendを使いました。
しかし、Blendで回転のアニメーションを付ける手順がわからず、
Blendで出力したコードに、手書きで編集・追加しました。