Skip to content

Commit ee72b5a

Browse files
Fix design mode model selection (incorrectly using design model in tests)
1 parent 1fc6183 commit ee72b5a

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/Certify.UI.Shared/ViewModel/AppViewModel/AppViewModel.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4-
using System.Diagnostics;
4+
using System.ComponentModel;
55
using System.IO;
66
using System.Linq;
77
using System.Threading.Tasks;
@@ -53,14 +53,13 @@ public AppViewModel(ICertifyClient certifyClient)
5353
/// <returns></returns>
5454
public static AppViewModel GetModel()
5555
{
56-
var stack = new StackTrace();
57-
if (stack.GetFrames().Last().GetMethod().Name == "Main")
56+
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
5857
{
59-
return new AppViewModel();
58+
return new AppViewModelDesign();
6059
}
6160
else
6261
{
63-
return new AppViewModelDesign();
62+
return new AppViewModel();
6463
}
6564
}
6665

src/Certify.UI.Shared/ViewModel/ManagedCertificateViewModel.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
45
using System.Linq;
56
using System.Threading.Tasks;
67
using System.Windows;
@@ -19,7 +20,6 @@ public class ManagedCertificateViewModel : BindableBase
1920
/// <summary>
2021
/// Provide single static instance of model for all consumers
2122
/// </summary>
22-
//public static AppModel AppViewModel = new DesignViewModel(); // for UI testing
2323
public static ManagedCertificateViewModel Current = ManagedCertificateViewModel.GetModel();
2424

2525
private Certify.UI.ViewModel.AppViewModel _appViewModel => ViewModel.AppViewModel.Current;
@@ -449,14 +449,13 @@ public int? PercentageLifetimeElapsed
449449

450450
public static ManagedCertificateViewModel GetModel()
451451
{
452-
var stack = new System.Diagnostics.StackTrace();
453-
if (stack.GetFrames().Last().GetMethod().Name == "Main")
452+
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
454453
{
455-
return new ManagedCertificateViewModel();
454+
return new ManagedCertificateViewModelDesign();
456455
}
457456
else
458457
{
459-
return new ManagedCertificateViewModelDesign();
458+
return new ManagedCertificateViewModel();
460459
}
461460
}
462461

0 commit comments

Comments
 (0)