1
メッセージセンターで表示モデルを使用すると、表示されないエントリが表示されます。何が間違っているのかを教えてください私はする必要があります。私はエントリがメッセージングセンターの価値を見つけることができないと思う。xamarin.forms - メッセージセンターがデータをエントリに渡す
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Data1.Views.Page1">
<ContentPage.Content>
<ListView x:Name = "lstView" ItemTapped="OnItemTapped" />
</ContentPage.Content>
</ContentPage>
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
lstView.ItemsSource = new List<string>() { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
}
void OnItemTapped(object sender, ItemTappedEventArgs e)
{
if (e == null) return; // has been set to null, do not 'process' tapped event
Debug.WriteLine(e.Item);
((ListView)sender).SelectedItem = null; // de-select the row
var person = new Person
{
Name = e.Item.ToString()
};
MessagingCenter.Send<Page1, string>(this, "Hi", e.Item.ToString());
Navigation.PushModalAsync(new Page2());
}
}
public partial class Page2 : ContentPage
{
public Page2()
{
InitializeComponent();
MessagingCenter.Subscribe<Page1, string>(this, "Hi", (sender, arg) =>
{
txttest.Text = arg;
});
}
}
それを試してみますまだメッセージを受け取ることはできません。 MessagingCenterは、今後の配信のためにメッセージをキューに入れません。このシナリオでは、値をPage2のコンストラクタのパラメータとして渡すほうがはるかに簡単です。 – Jason
これを使ってエントリにバインドしても、何もしません。public class MainViewModel { public Person Person {get;セット; } 公共MainViewModel(){ MessagingCenter.Subscribe(この、 "こんにちは"、(送信者、引数)=> { 人=新しい人 { 名= argを };} ) ; } } –
文脈でそのコードを見ることなく、私が言及した問題に対処しているかどうかはわかりません。 – Jason