TargetUpdated イベントが完璧に思えるという問題に遭遇しました。残念ながら、Multibinding には TargetUpdated プロパティがないようです。これをまだ設定する方法はありますか、それとも完全に別の解決策を見つける必要がありますか?
役立つコードをいくつか紹介します
バインディングはこちら...
<RotateTransform x:Name="LeftNeedle">
<RotateTransform.Angle>
<MultiBinding Converter="{StaticResource VoltageRatioConverter}" NotifyOnTargetUpdated="True" >
<Binding ElementName="root" Path="Running" />
<Binding ElementName="root" Path="Incoming" />
</MultiBinding>
</RotateTransform.Angle>
次に、値コンバーターがあります...
public class VoltageRatioConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values == null || values.Count((x) => x != null) != 2)
return 0.0;
double running = System.Convert.ToDouble(values[0]);
double incoming = System.Convert.ToDouble(values[1]);
return ((running / incoming) - 1);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
そして、私が探しているのは、その結果の数値を取得し、それを関数に渡して角度/アニメーションを更新することです
private static void OnAngleValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
GaugeCluster gauge = o as GaugeCluster;
if ((double)e.NewValue > 70)
{
VisualStateManager.GoToState(gauge, "RightWobble", false);
}
else if ((double)e.NewValue < -70)
{
VisualStateManager.GoToState(gauge, "LeftWobble", false);
}
else
{
if ((double)e.OldValue > 70 || (double)e.OldValue < -70)
{
VisualStateManager.GoToState(gauge, "StandingState", false);
}
}
}
^ この関数は、2 つの依存関係プロパティのいずれかからのコールバックにすることで、実際に機能することを確認するためにテストしていました。理想的には、TargetUpdated イベントで使用したいのは関数本体です。