1
このプロジェクトでは、XamarinでPrism.Unity.Formsを使用しています。 Client.Id
プロパティが変更されたときに、ビューを更新するにはどうすればよいですか? {Binding Client.Id}
(Guidオブジェクト)から{Binding Client.Name}
(文字列)にXAMLを変更すると、ビューが更新されます。Xamarinフォームビューがカスタムクラスで更新されない
public class CreateClientViewModel : BindableBase
{
private Client _client;
public Client Client {
get => _client;
set => SetProperty(ref _client, value);
}
private async void FetchNewClient()
{
Client = new Client{
Id = new Guid.Parse("501f1302-3a45-4138-bdb7-05c01cd9fe71"),
Name = "MyClientName"
};
}
}
これは動作します
<Entry Text="{Binding Client.Name}"/>
これは私がカスタムクラスでGuid
を包み、オーバーライドのでToString
方法がClient.Id
プロパティに呼び出されている知っている
<Entry Text="{Binding Client.Id}"/>
しませんToString
メソッドですが、ビューはまだ更新されません。
public class CreateClientViewModel : BindableBase
{
private Client _client;
public Client Client {
get => _client;
set => SetProperty(ref _client, value);
}
//This method will eventually make an API call.
private async void FetchNewClient()
{
Client = new Client{
Id = new ClientId{
Id = new Guid.Parse("501f1302-3a45-4138-bdb7-05c01cd9fe71")
},
Name = "MyClientName"
};
}
}
public class ClientId
{
public Guid Id { get; set }
public override string ToString()
{
//This method gets called
Console.WriteLine("I GET CALLED");
return Id.ToString();
}
}
App.xaml
にコンバータを登録しました –