私はxamarin.Formsのpubnubを使ってチャットアプリケーションを試しています。ブレークポイントを維持することで理解できるチャンネルにログインできます。今では人のリストを取得しようとしています誰が自分のチャンネルにログインしていたのですか?ログインユーザーのリストを取得する方法-pubnub
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label Text="Welcome" TextColor="Blue" HorizontalOptions="Center" VerticalOptions="Center">
<Label.FontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>
<OnPlatform x:TypeArguments="x:Double" iOS="20" Android="20" WinPhone="20" />
</OnIdiom.Phone>
<OnIdiom.Tablet>
<OnPlatform x:TypeArguments="x:Double" iOS="30" Android="30" WinPhone="30" />
</OnIdiom.Tablet>
</OnIdiom>
</Label.FontSize>
</Label>
<ListView x:Name="LoginUserList" ItemsSource="{Binding LoginUserList}"ItemSelected="LoginUserList_OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding UserName}" TextColor="SkyBlue" FontSize="20" HorizontalOptions="Center" VerticalOptions="Center"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
ここでは、ログインしているユーザーの一覧を表示する方法を示します。
public class ChatListViewModel : INotifyPropertyChanged
{
private List<UserDto> _loginUserList;
private string _offlineImageSource;
private bool _offlineVisibility;
private string _userName;
public ChatListViewModel()
{
InitializeData();
GetAllUsersFromServer();
}
public event PropertyChangedEventHandler PropertyChanged;
public List<UserDto> LoginUserList
{
get { return _loginUserList; }
set
{
_loginUserList = value;
OnPropertyChanged();
}
}
public string OfflineImageSource
{
get { return _offlineImageSource; }
set
{
_offlineImageSource = value;
OnPropertyChanged();
}
}
public string UserName
{
get { return _userName; }
set
{
_userName = value;
OnPropertyChanged();
}
}
public bool OfflineVisibility
{
get { return _offlineVisibility; }
set
{
_offlineVisibility = value;
OnPropertyChanged();
}
}
private async void GetAllUsersFromServer()
{
LoginUserList = await UserService.Instance.GetAllUsers();
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void InitializeData()
{
OfflineImageSource = "BlackCircle.png";
}
}
ここは、リスト表示のためのViewModelです。
をあなたはLoginUserList ItemSourceにユーザーデータをバインドすることがありますか? –
実際に私はwebApisからの登録ユーザのリストを表示するために、viewmodelのアイテムソースをバインドしています。私はpubnub apis there.Butを使用していませんでしたが、今はpubnubからバインドしたいのですが、 – sahithi
あなたの質問にあなたのビューモデルコードを追加してください。 –