views:

518

answers:

2

I have this WPF Window:

public Window1()
{
    InitializeComponent();
    this.Content = new TheForm();
}

Which loads this UserControl:

<UserControl x:Class="TestAutomaticUpdate82828.TheForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <DockPanel Margin="10" LastChildFill="True" VerticalAlignment="Top">
        <TextBox DockPanel.Dock="Top" Text="{Binding InputText, UpdateSourceTrigger=PropertyChanged}" Height="25" Width="100" HorizontalAlignment="Left" Margin="0 0 0 3"/>
        <TextBox DockPanel.Dock="Top" Text="{Binding OuputText}" Height="25" Width="100" HorizontalAlignment="Left" Margin="0 0 0 3"/>
    </DockPanel>
</UserControl>

Which has this code-behind:

using System.Windows.Controls;
using System.Windows.Input;
using System.ComponentModel;

namespace TestAutomaticUpdate82828
{

    public partial class TheForm : UserControl, INotifyPropertyChanged
    {

        #region ViewModelProperty: InputText
        private string _inputText;
        public string InputText
        {
            get
            {
                return _inputText;
            }

            set
            {
                _inputText = value;
                OnPropertyChanged("InputText");
                OutputText = "changed";
            }
        }
        #endregion

        #region ViewModelProperty: OutputText
        private string _outputText;
        public string OutputText
        {
            get
            {
                return _outputText;
            }

            set
            {
                _outputText = value;
                OnPropertyChanged("OutputText");
            }
        }
        #endregion

        public TheForm()
        {
            InitializeComponent();
            DataContext = this;
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

    }
}

However, when I run the application and type text into the InputText TextBox, I see that it steps into the Set property of InputText, but not further into the Set property of OutputText and hence, OutputText is not updated.

I had this working in a View / ViewModel structure, but why isn't it working in this code-behind scenario?

A: 

Maybe because I wrote OuputText instead of OutputText in my XAML (!).

My bad, would be nice if there was some intellisense support there though...

Edward Tanguay
A: 

Expression Blend has Intellisense support for XAML.

ChrisF
as far as I have seen, vs2010 beta 2 has intellisense support for e.g. Mode=TwoWay/OneWay, but not for reading your custom bound properties out of the DataContext, will have to try that in the newest Blend, thanks
Edward Tanguay