確かにこの質問は数千回議論されていましたが、私のニーズに適した解決策を見つけることはできません。私はSilverLIghtが初めてで、MVVMを使い始めようとしました。viewModelのプロパティを介したデータバインド
public class MyViewModel
{
private IRepository _Repository;
public string CountText { get; set; }
public MyViewModel (IRepository repository)
{
_Repository = repository;
CountText = "test ctor";
}
public void MyButtonCommand()
{
_Repository.GetResult((Result r) => MyActionAsync(r), (Exception e) => ManageException(e));
}
public void MyActionAsync(SchedeConsunitiviResult result)
{
CountText = string.Format("{0} items", result.Count);
}
public void ManageException(Exception e)
{
//to log the exception here and display some alert message
}
}
とここに私のXAML: したがって、私は、次のビューモデルでした
<sdk:Label Content="{Binding Path=CountText, Mode=TwoWay}" Grid.Row="3" Height="28" HorizontalAlignment="Left" Margin="12,142,0,0" Name="label1" VerticalAlignment="Top" Width="120" Grid.ColumnSpan="2" />
をCountTextの最初のインスタンス化は、ラベルに表示されます。しかし、非同期メソッドの後の2番目のメソッドは、LAbelの内容を変更しません。このプロパティが変更されたビューを伝えるために、PropertyChangedのようなメカニズムを追加する必要がありますか?もしそうなら、私はxamlだけを使ってそれをどうやって行うことができますか?あなたの助けのための
THX
YouhouでのPropertyChangedのような仕組みが必要です知っているように、それは魔法のように動作します! – Arthis