uwp - ReactiveUI 和 UWP – 这些绑定警告/错误来自哪里?
问题描述
我正在尝试在 UWP 中创建我的第一个 ReactiveUI 应用程序,但遇到了一些我不知道该怎么处理的意外警告/错误。
我在 UWP(最低版本 10/1809/17763,最高版本 10/2004/19041)应用程序中使用 ReactiveUI 版本 12.1.1。
我一直在遵循(尽管我认为我做得正确)这里的说明:https ://www.reactiveui.net/docs/handbook/data-binding/microsoft-store
这是页面定义:
<Page
x:Class="UwpReactiveUiTest.Views.GridsView"
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:local="using:UwpReactiveUiTest.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid>
<Slider
x:Name="slider"
Maximum="50"
Minimum="0"
Value="25" />
</Grid>
</Page>
这是页面背后的代码:
public sealed partial class GridsView : Page, IViewFor<GridsViewModel>
{
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register(
nameof(ViewModel),
typeof(GridsViewModel),
typeof(GridsView),
new PropertyMetadata(null)
);
public GridsViewModel ViewModel
{
get => (GridsViewModel)GetValue(ViewModelProperty);
set => SetValue(ViewModelProperty, value);
}
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (GridsViewModel)value;
}
public GridsView()
{
this.InitializeComponent();
ViewModel = new GridsViewModel();
}
}
这是视图模型:
public class GridsViewModel : ReactiveObject
{
private double _sliderValue;
public double SliderValue
{
get => _sliderValue;
set => this.RaiseAndSetIfChanged(ref _sliderValue, value);
}
public GridsViewModel()
{
}
}
当我运行应用程序时,一切都很好;正如预期的那样,我在输出中收到很多“正在加载 DLL”消息,但仅此而已。
但是,只要我将绑定添加到 View 构造函数中,例如:
public GridsView()
{
this.InitializeComponent();
ViewModel = new GridsViewModel();
this.WhenActivated(disposableRegistration =>
{
this.Bind(ViewModel,
viewModel => viewModel.SliderValue,
view => view.slider.Value)
.DisposeWith(disposableRegistration);
});
}
我在输出中得到这个:
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
LogHost: Initializing to normal mode
POCOObservableForProperty: The class UwpReactiveUiTest.Views.GridsView property slider is a POCO type and won't send change notifications, WhenAny will only return a single value!
我的问题是:
- 例外。 异常来自哪里,我可以/应该怎么做?
- POCO 警告。 为什么我会收到 POCO 警告,我可以/应该怎么做?
解决方案
- 异常,如果它们只发生在启动时已解决ReactiveUI 2395
- POCO 警告,这是一个警告,让您知道您的财产不会通知更改。它们可以被忽略。但是,如果您想知道为什么您的属性不会更新,这些警告通常会说明原因。我不知道你可以把它关掉,但这不是什么值得担心的事情。
推荐阅读
- css - 底部对齐 React Bootstrap Card.Img
- python - Python正则表达式查找单个字母基本方向
- python - 电报机器人 python 使用 user_id 授权用户
- python - 按特定顺序组织饼图中的颜色?
- c++ - 如何删除单个空白而不是多个?
- python - 如何在代码更新或服务器重新启动时在 Windows 中重新启动 Dramatiq?
- python - 在 pandas 中拆开 json 字典
- python - Spyder 不会运行已安装的模块 - Windows 10
- python - 模块“discord.ext.commands”没有属性“get_channel”
- python - 蟒蛇错误。预期二维数组,得到一维数组,如何解决?