This project is read-only.

Controls are not being bound when using White

Nov 28, 2011 at 10:29 PM
Edited Nov 28, 2011 at 10:37 PM


I have a wpf application with a simple window that shows a text in a textbox bound to a property of the ViewModel. When I execute the application I can see the text in the textbox, but when I execute a white based test, I have different results, at random:

  • most of the times, it's not bound and the test fails.
  • sometimes it's bound (I can see the text in the window raised by white), but white throws an exception when the code wants to get the window.
  • sometimes (really few) it works.

The code I'm trying to execute is this:

<Window x:Class="Sample.Tests.Wpf.MainWindow"  xmlns=""    xmlns:x="" Title="MainWindow" Height="350" Width="525">   
      <TextBox Height="23" HorizontalAlignment="Left" Margin="22,19,0,0" Name="name" Text="{Binding Path=CountryName}"  VerticalAlignment="Top" Width="120" />    

The code behind:

namespace Sample.Tests.Wpf
    public partial class MainWindow
        public MainWindow()
            Loaded += delegate { 
                                              DataContext = new MainWindowViewModel
                                                                    CountryName = "Argentina"


and the test looks like:

var app = Application.Launch("Sample.Tests.Wpf.exe");
var window = app.GetWindow("MainWindow");
var textbox = window.Get<TextBox>("name");
Assert.AreEqual("Argentina", textbox.Text);

Any idea? Thanks in advance!