Ошибка "Unsupported expression of type 'Constant'. Did you miss the member access prefix in the expression?" С#
У меня при работе программы появляется такая ошибка. "Unsupported expression of type 'Constant'. Did you miss the member access prefix in the expression?" При сборке проекта ее нет. Я пытаюсь привязать кнопки в WPF с командами ReactiveCommand
Вот код представления
public partial class Home : ReactiveWindow<HomeViewModel>
{
public Home()
{
DataContext = ViewModel = new HomeViewModel();
InitializeComponent();
this.WhenActivated(disposable =>
{
this.Bind(this.ViewModel, x => x.nameUser, x => x.TextBlock1.Text);
this.BindCommand(this.ViewModel, x => x.Message, x => MessageButton);
this.Bind(this.ViewModel, x=> x.Button1Text, x=> MessageButton.Content);
this.BindCommand(this.ViewModel, x => x.EditInformation, x => EditInformationButton);
this.Bind(this.ViewModel, x => x.Button2Text, x => EditInformationButton.Content);
this.BindCommand(this.ViewModel, x => x.OrderNewProject, x => OrderNewProjectButton);
this.Bind(this.ViewModel, x => x.Button3Text, x => OrderNewProjectButton.Content);
this.BindCommand(this.ViewModel, x => x.ViewProgress, x => ViewProgressButton);
this.Bind(this.ViewModel, x => x.Button4Text, x => ViewProgressButton.Content);
});
}
}
Вот код моей ViewModel
public class HomeViewModel : ReactiveObject
{
public ReactiveCommand<Unit, Unit> ViewProgress { get; set; }
public ReactiveCommand<Unit, Unit> Message { get; }
public ReactiveCommand<Unit, Unit> EditInformation { get; }
public ReactiveCommand<Unit, Unit> OrderNewProject { get; }
public HomeViewModel()
{
var PublicDataConnecton = new DataConnecton();
GlobalData.name = PublicDataConnecton.GetUserName(GlobalData.login, GlobalData.password) ;
GlobalData.id = Convert.ToInt32(PublicDataConnecton.GetUserId(GlobalData.login, GlobalData.password)) ;
nameUser = GlobalData.name;
if (GlobalData.id >9999)
{
Button1Text = "Написать сообщение";
Button2Text = "Редактировать личную информацию";
Button3Text = "Заказать новый проект";
Button4Text = "Ход разработки проектов";
}
ViewProgress = ReactiveCommand.Create(() =>
{ Console.WriteLine("ss"); });
Message = ReactiveCommand.Create(() =>
{ Console.WriteLine("ss"); });
EditInformation = ReactiveCommand.Create(() =>
{ Console.WriteLine("ss"); });
OrderNewProject = ReactiveCommand.Create(() =>
{ Console.WriteLine("ss"); });
}
[Reactive]
public string nameUser { get; set; }
[Reactive]
public string Button1Text { get; set; }
[Reactive]
public string Button2Text { get; set; }
[Reactive]
public string Button3Text { get; set; }
[Reactive]
public string Button4Text { get; set; }
}
В работе используется Фреймворк ReactiveUI. А ошибки в строчках
this.BindCommand(this.ViewModel, x => x.Message, x => MessageButton);
this.Bind(this.ViewModel, x=> x.Button1Text, x=> MessageButton.Content);
this.BindCommand(this.ViewModel, x => x.EditInformation, x => EditInformationButton);
this.Bind(this.ViewModel, x => x.Button2Text, x => EditInformationButton.Content);
this.BindCommand(this.ViewModel, x => x.OrderNewProject, x => OrderNewProjectButton);
this.Bind(this.ViewModel, x => x.Button3Text, x => OrderNewProjectButton.Content);
this.BindCommand(this.ViewModel, x => x.ViewProgress, x => ViewProgressButton);
this.Bind(this.ViewModel, x => x.Button4Text, x => ViewProgressButton.Content);
Ответы (1 шт):
Автор решения: Khamidov
→ Ссылка
так не делается
this.BindCommand(this.ViewModel, x => x.EditInformation, x => EditInformationButton);
this.Bind(this.ViewModel, x=> x.Button1Text, x=> MessageButton.Content);
так делается
this.BindCommand(this.ViewModel, x => x.EditInformation, x => x.EditInformationButton);
this.Bind(this.ViewModel, x=> x.Button1Text, x=> x.MessageButton.Content);