C# 错误:“您需要调用RxApp.ConfigureServiceLocator来设置服务位置”
以下代码在问题标题中提供了运行时错误。不过,当我在MainWindow构造函数中注释掉OneWayBind调用时,应用程序运行时不会出错。有什么想法吗 窗户 视图模型C# 错误:“您需要调用RxApp.ConfigureServiceLocator来设置服务位置”,c#,reactiveui,C#,Reactiveui,以下代码在问题标题中提供了运行时错误。不过,当我在MainWindow构造函数中注释掉OneWayBind调用时,应用程序运行时不会出错。有什么想法吗 窗户 视图模型 非常感谢你!我只希望ReactiveUI4.5.0有当前的WPF实现示例!它们都过时了六个月甚至更长 您的项目中是否有对ReactiveUI.Xaml的引用?谢谢您,Paul。NuGet表示已安装并正确引用了ReactiveUI.Xaml。我通过NuGet卸载并重新安装ReactiveUI纠正了这个问题。 public parti
非常感谢你!我只希望ReactiveUI4.5.0有当前的WPF实现示例!它们都过时了六个月甚至更长 您的项目中是否有对ReactiveUI.Xaml的引用?谢谢您,Paul。NuGet表示已安装并正确引用了ReactiveUI.Xaml。我通过NuGet卸载并重新安装ReactiveUI纠正了这个问题。
public partial class MainWindow : Window, IViewFor<MainViewModel>
{
public MainWindow()
{
ViewModel = new MainViewModel();
InitializeComponent();
this.OneWayBind(ViewModel, x => x.ContentItems, x => x.panelDemo.ItemsSource);
}
public MainViewModel ViewModel
{
get { return (MainViewModel)GetValue(ViewModelProperty); }
set { SetValue(ViewModelProperty, value); }
}
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(MainViewModel), typeof(MainWindow), new PropertyMetadata(null));
object IViewFor.ViewModel
{
get { return ViewModel; }
set { ViewModel = (MainViewModel)value; }
}
}
public class ContentItem
{
public BitmapImage Image { get; set; }
public string Name { get; set; }
}
public class MainViewModel : ReactiveObject
{
string _Directory;
public string Directory
{
get { return _Directory; }
set { this.RaiseAndSetIfChanged(x => x.Directory, value); }
}
bool _IsBusy;
public bool IsBusy
{
get { return _IsBusy; }
set { this.RaiseAndSetIfChanged(x => x.IsBusy, value); }
}
ObservableAsPropertyHelper<IList<ContentItem>> _ContentItems;
public IList<ContentItem> ContentItems
{
get { return _ContentItems.Value; }
}
public MainViewModel()
{
this.WhenAny(x => x.Directory, x => x.Value)
.Do(_ => IsBusy = true)
.Select(GetImages)
.Do(_ => IsBusy = false);
}
IObservable<IList<ContentItem>> GetImages(string directory)
{
return new DirectoryInfo(directory).GetFiles().ToList().ToObservable()
.Select(x => new ContentItem
{
Image = new BitmapImage(new Uri(x.FullName)),
Name = x.Name
}).ToList();
}
}