New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2枚目以降のウィンドウでバリデーションエラー赤枠が残る #258
Comments
ViewModelのコンストラクタを以下のように変更することで解決しそうですが、どうでしょうか。 public ViewModel() => RP_Text = new ReactiveProperty<string>(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreInitialValidationError)
.SetValidateAttribute(() => RP_Text);
参考 |
説明不足ですいません。 なぜ違いが出るのか。 というのがこのissueの目的です。 |
あれこれやっていて気が付いたのですが、これに関連した制限事項ということなんでしょうか?
コードで 現状をまとめます。
|
情報提供ありがとうございます。 今回、追加で調査したところ以下のような Scheduler を自前で実装して お手数をおかけしますが、そちらでも挙動が改善されるか確認してみていただけないでしょうか? using System;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Threading;
using System.Windows.Threading;
namespace Reactive.Bindings.Schedulers
{
public class WpfScheduler : LocalScheduler
{
private readonly Dispatcher _dispatcher;
private readonly DispatcherSynchronizationContext _context;
public WpfScheduler(Dispatcher dispatcher)
{
_dispatcher = dispatcher;
_context = new DispatcherSynchronizationContext(dispatcher);
}
public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
if (_dispatcher.CheckAccess())
{
return action(this, state);
}
var d = new SingleAssignmentDisposable();
_context.PostWithStartComplete(() =>
{
if (!d.IsDisposed)
{
d.Disposable = action(this, state);
}
});
return d;
}
public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
var dt = Scheduler.Normalize(dueTime);
if (dt.Ticks == 0)
{
return Schedule(state, action);
}
// Note that avoiding closure allocation here would introduce infinite generic recursion over the TState argument
return DefaultScheduler.Instance.Schedule(state, dt, (_, state1) => Schedule(state1, action));
}
}
internal static class SynchronizationContextExtensions
{
public static void PostWithStartComplete<T>(this SynchronizationContext context, Action<T> action, T state)
{
context.OperationStarted();
context.Post(
o =>
{
try
{
action((T)o!);
}
finally
{
context.OperationCompleted();
}
},
state
);
}
public static void PostWithStartComplete(this SynchronizationContext context, Action action)
{
context.OperationStarted();
context.Post(
_ =>
{
try
{
action();
}
finally
{
context.OperationCompleted();
}
},
null
);
}
}
} |
以下のような問題の合わせ技で自作 Scheduler を作らないとうまく動きませんでした。
|
お時間を割いていただきありがとうございます。
|
WPF の場合は
|
余談ですが、最初の Window だと赤枠が出ないのは最初の Window が作成されるタイミングで ReactiveProperty が使う Scheduler が初期化されます。その時に 2 つ目以降の Window が表示されるときには |
なるほどコレクションでまずいのですね。
了解しました。 大変勉強になりました。ありがとうございました。 |
ご本人の確認も取れましたので閉じます。 |
C# - ReactiveProperty バリデーション 画面起動前に値をセットすると赤枠が消えない|teratail
こちらが元なのですが初めに出る
Window
は問題ないのですが、ボタンを押して新たにWindow
を出すとReactiveProperty
側だけ赤枠が出るという症状が出ています(デザイナでも赤枠が出ます)何か心当たりはあるでしょうか?
以下再現するコードです。
どう関係するのかわかりませんが、xamlでの
DataContext
セットをやめてコードでや
とすると問題が出ません。
しかし
とすると再発します(デザイナでは赤枠は出ません)
The text was updated successfully, but these errors were encountered: