本文介绍了依赖属性的reactiveui whenany的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个文本框和 ReactiveUI 的简单 WPF 应用程序.我尝试使用 WhenAny

I have simple WPF app with two textboxes and ReactiveUI. I try to lookup for dependency property of first textbox by using WhenAny

 public partial class MainWindow : Window
{
    public MainWindow()
    {
        RxApp.DeferredScheduler = DispatcherScheduler.Current;
        InitializeComponent();
        Text1.WhenAny(i => i.Text, i => i.Value).Subscribe(_ => SomeMethod());

    }

    void SomeMethod()
    {
        MessageBox.Show("Boom!");
    }

}

我的表单代码是

<Window x:Class="TestObservable.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <TextBox Name="Text1" Grid.Column="0"></TextBox>
    <TextBox Name="Text2" Grid.Column="1"></TextBox>

</Grid>

但是当我更改 TextBox 文本时,它不会显示给我

BUT When I change TextBox Text it doesn't show to me

有什么问题吗?

推荐答案

试试这个:

this.WhenAny(x => x.Text1.Text, x => x.Value);

如果它不起作用,我相信您是被 ReactiveUI 4.1 中的错误所困扰.升级到 4.2(几天前发布)可能会修复它.

If it doesn't work, I believe you're being bitten by a bug in ReactiveUI 4.1. Upgrading to 4.2 (released a few days ago) may fix it.

这篇关于依赖属性的reactiveui whenany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:58