CustomControlを含むリストで構成されるLightSwitch画面があります。このCustomControlには、TwoWayバインディングを介してエンティティのプロパティにバインドされる一連の依存関係プロパティがあります。
CustomControlの依存関係プロパティの1つに、LightSwitchページのメソッドを実行するPropertyChangedCallbackがあります。次に、リストがバインドされているアイテムのコレクション全体でいくつかの計算が実行されます。
ほとんどの場合、これは問題ありませんが、場合によっては、計算をトリガーした変更がCustomControlのTwoWayバインディングからエンティティにプッシュされる前に計算が実行されるように見えます。これを解決するにはどうすればよいですか?CustomControl依存関係プロパティへの変更がTwoWayバインディングからプッシュされた後、LightSwitchページ内のコードが実行されることを確認する必要があります。
次の方法でCustomControlにバインディングを作成します。
SetBinding(AxleNumberProperty, new Binding("Value.Number") { Mode = BindingMode.TwoWay });
依存関係プロパティは次のようになります。
public static readonly DependencyProperty AxleNumberProperty =
DependencyProperty.Register("AxleNumber", typeof(int), typeof(AxleViewer), new PropertyMetadata((d, e) => ((AxleViewer)d).RecalculateSquare()));
依存関係プロパティのコールバックは次のようになります。
private void RecalculateSquare()
{
IContentItem contentItem = (IContentItem)DataContext;
IScreenDetails screenDetails = contentItem.Screen.Details;
screenDetails.Dispatcher.BeginInvoke(() => screenDetails.Commands["UpdateSquare"].Execute());
}
次に、画面内に次のように表示されます。
partial void UpdateSquare_Execute()
{
// perform calculation on this.Axles
}