|
| 1 | +// Copyright (c) 2023 .NET Foundation and Contributors. All rights reserved. |
| 2 | +// Licensed to the .NET Foundation under one or more agreements. |
| 3 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 4 | +// See the LICENSE file in the project root for full license information. |
| 5 | + |
| 6 | +using System.Windows; |
| 7 | +using System.Windows.Controls; |
| 8 | + |
| 9 | +namespace ReactiveUI.Tests.Wpf; |
| 10 | + |
| 11 | +public static class FakeViewWithContract |
| 12 | +{ |
| 13 | + internal const string ContractA = "ContractA"; |
| 14 | + internal const string ContractB = "ContractB"; |
| 15 | + |
| 16 | + public class MyViewModel : ReactiveObject |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Used as the default view with no contracted. |
| 22 | + /// </summary> |
| 23 | + public class View0 : UserControl, IViewFor<MyViewModel> |
| 24 | + { |
| 25 | + |
| 26 | + // Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc... |
| 27 | + public static readonly DependencyProperty ViewModelProperty = |
| 28 | + DependencyProperty.Register("ViewModel", typeof(MyViewModel), typeof(View0), new PropertyMetadata(null)); |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Gets or sets the ViewModel. |
| 32 | + /// </summary> |
| 33 | + public MyViewModel? ViewModel |
| 34 | + { |
| 35 | + get { return (MyViewModel)GetValue(ViewModelProperty); } |
| 36 | + set { SetValue(ViewModelProperty, value); } |
| 37 | + } |
| 38 | + |
| 39 | + object? IViewFor.ViewModel { get => ViewModel; set => ViewModel = (MyViewModel?)value; } |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// the view with ContractA. |
| 44 | + /// </summary> |
| 45 | + public class ViewA : UserControl, IViewFor<MyViewModel> |
| 46 | + { |
| 47 | + |
| 48 | + // Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc... |
| 49 | + public static readonly DependencyProperty ViewModelProperty = |
| 50 | + DependencyProperty.Register("ViewModel", typeof(MyViewModel), typeof(ViewA), new PropertyMetadata(null)); |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Gets or sets the ViewModel. |
| 54 | + /// </summary> |
| 55 | + public MyViewModel? ViewModel |
| 56 | + { |
| 57 | + get { return (MyViewModel)GetValue(ViewModelProperty); } |
| 58 | + set { SetValue(ViewModelProperty, value); } |
| 59 | + } |
| 60 | + |
| 61 | + object? IViewFor.ViewModel { get => ViewModel; set => ViewModel = (MyViewModel?)value; } |
| 62 | + } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// the view as ContractB. |
| 66 | + /// </summary> |
| 67 | + public class ViewB : UserControl, IViewFor<MyViewModel> |
| 68 | + { |
| 69 | + |
| 70 | + // Using a DependencyProperty as the backing store for ViewModel. This enables animation, styling, binding, etc... |
| 71 | + public static readonly DependencyProperty ViewModelProperty = |
| 72 | + DependencyProperty.Register("ViewModel", typeof(MyViewModel), typeof(ViewB), new PropertyMetadata(null)); |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Gets or sets the ViewModel. |
| 76 | + /// </summary> |
| 77 | + public MyViewModel? ViewModel |
| 78 | + { |
| 79 | + get { return (MyViewModel)GetValue(ViewModelProperty); } |
| 80 | + set { SetValue(ViewModelProperty, value); } |
| 81 | + } |
| 82 | + |
| 83 | + object? IViewFor.ViewModel { get => ViewModel; set => ViewModel = (MyViewModel?)value; } |
| 84 | + } |
| 85 | +} |
0 commit comments