Пытаюсь отобразить данные не в главном окне, но не могу понять, почему они не отображаются. Есть класс:
public class StudentModel : INotifyPropertyChanged
{
public StudentModel(int remoteId, int receiverId)
{
RemoteId = (ushort)remoteId;
ReceiverId = receiverId;
}
public StudentModel()
{
}
public List<string> textString { get; set; } = new List<string>();
protected virtual void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void QuestionsAdd(string text)
{
Questions.Add($"{Questions.Count + 1}. " + $" {text}");
}
}
В другом классе я добавляю в коллекцию объекты:
public class MainWindowViewModel
{
public ObservableCollection<StudentModel> Students { get; set; } = new ObservableCollection<StudentModel>();
IFileService _fileService;
IDialogService _dialogService;
private readonly DeviceManager deviceManager = new DeviceManager(new VotumDevicesManager());
public MainWindowViewModel() { }
public MainWindowViewModel(IDialogService dialogService, IFileService fileService)
{
_dialogService = dialogService;
_fileService = fileService;
for (int i = 0; i < 32; i++)
{
Students.Add(new StudentModel());
}
deviceManager.votumManager.ButtonClicked += VotumManager_ButtonClicked;
}
private void GettingAQuestionsRemotely(int RemoteId, ButtonClickEventArgs e)
{
if (e.IsT2TextPresent && e.Button.Type == ButtonType.PauseT2)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
//**Добавляем в коллекцию объекты**
Students.FirstOrDefault(x => x.RemoteId.Equals(Convert.ToUInt16(RemoteId)))?.QuestionsAdd(e.T2Text);
var std = Students.FirstOrDefault(x => x.RemoteId.Equals(Convert.ToUInt16(RemoteId)));
if (std != null)
{
std.Question = e.T2Text;
OnTick -= std.UpTime;
}
}));
}
}
public RelayCommand<StudentModel> questionCmd = null;
public RelayCommand<StudentModel> QuestionCmd => questionCmd ?? (questionCmd = new RelayCommand<StudentModel>((param) =>
{
new QuestionView().ShowDialog();
},
(param) =>
{
return (param != null && param.Questions.Count == 0) ? false : true;
}
));
}
XAML:
<Window x:Class="Guess.Yourself.QuestionView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Guess.Yourself"
mc:Ignorable="d"
Title="Архив вопросов"
SizeToContent="WidthAndHeight"
Topmost="True"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Window.DataContext>
<local:StudentModel/>
</Window.DataContext>
<Grid>
<ListView x:Name="lv" Background="Gray" Height="300" MaxHeight="300" MinWidth="250" ItemsSource="{Binding Questions}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="32" Foreground="White"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
Window.DataContext
из разметки