18

WinRT リファレンスでEventTriggerを見つけることができましたが、 DataTrigger を見つけることができませんでした。アプリケーションでも使用できませんでした。

WinRT で DataTrigger が本当に欠落していることを確認できる人はいますか? WinRT で使用できるトリガーは EventTrigger だけですか?

4

5 に答える 5

20

DataTrigger は現在、WinRT XAML ではサポートされていません。

マイク・ブラウンによる補遺

DataTrigger API はVisualStateManagerに置き換えられました。データ トリガーと同様の API は、Blend SDK for Silverlight によって提供されました。Attached Behavior Pattern は WinRT で機能するため、同じことが可能です。

于 2011-09-16T15:18:16.853 に答える
3

WinRT でトリガーを実装しているように見えるこのプロジェクトはどうですか: http://winrttriggers.codeplex.com/

于 2013-10-11T14:59:46.920 に答える
2

いつ変更されたのかわかりませんが、それらDataTriggerBehaviorGoToStateAction組み合わせることで問題が解決するはずです...

名前空間のインポート

xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" 
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"

ViewSateManager をルート要素に配置

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="Common">
        <VisualStateGroup.Transitions>
            <VisualTransition GeneratedDuration="0" To="Online">
                <Storyboard>
                    <ColorAnimation Duration="0" To="Lime" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Name" />
                </Storyboard>
            </VisualTransition>
            <VisualTransition GeneratedDuration="0" To="Offline">
                <Storyboard>
                    <ColorAnimation Duration="0" To="Red" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Name" />
                </Storyboard>
            </VisualTransition>
        </VisualStateGroup.Transitions>
        <VisualState x:Name="Online" />
        <VisualState x:Name="Offline" />
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Interactivity:Interaction.Behaviors>
    <Core:DataTriggerBehavior Binding="{Binding Active}" Value="True">
        <Core:GoToStateAction StateName="Online" />
    </Core:DataTriggerBehavior>
    <Core:DataTriggerBehavior Binding="{Binding Active}" Value="False">
        <Core:GoToStateAction StateName="Offline" />
    </Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
于 2014-06-11T20:17:21.167 に答える
0

あなたのために働くかもしれない別の回避策を実装しました。手順:

  1. UserControl を (ゼロから、または継承して) 作成し、コード ビハインド C# をコントロールに記述できるようにします。
  2. トリガーするデータ バインディングのコード ビハインドで DependencyProperty を作成します。
  3. DependencyProperty の PropertyChangedCallback メソッドを使用して、コードで実行する必要があることをコントロールに実装します。
  4. XAML の DependencyProperty を、トリガーするデータにバインドします。

DataTrigger ほどきれいではありませんが、それほど悪くはなく、うまく機能します (少なくとも私にとっては)。

XAML での宣言 (DataContext は既にビューモデル オブジェクトに設定されています):

<local:PlayButton IsPlaying="{Binding IsPlaying}"/>

ストーリーボードをトリガーして状態を変更する DependencyProperty の例:

// Use this to implement storyboard changing in W8 since triggers are not supported
public static readonly DependencyProperty IsPlayingProperty = DependencyProperty.Register(
      "IsPlaying",
      typeof(bool),
      typeof(PlayButton),
      new PropertyMetadata(null,
          new PropertyChangedCallback(OnIsPlayingChanged)
      ));

private static void OnIsPlayingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    PlayButton pb = (PlayButton)d;
    bool isPlaying = (bool)e.NewValue;

    if (isPlaying == false)
        pb.GotoPlay.Begin();
    else
        pb.GotoPause.Begin();
}

public bool IsPlaying
{
    get { return (bool)GetValue(IsPlayingProperty); }
    set { SetValue(IsPlayingProperty, value); }
}
于 2012-09-22T18:08:37.060 に答える
-1

object.Triggersの代わりにVisualStateを使用できます。Windows8のトリガーは次のとおりです。

<ControlTemplate TargetType="Button">
  <Grid>
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">
        <VisualStateGroup.Transitions>
          <!--Take one half second to transition to the PointerOver state.-->
          <VisualTransition To="PointerOver" GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <VisualState x:Name="PointerOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush"
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </Grid>
</ControlTemplate>
于 2012-07-12T19:23:30.900 に答える