locked
Binding a UI element to a variable.

    Question

  • I want to display the contents of an object (defined in C++) in my XAML page.

    My test page:

    <Page
        x:Class="BindingTest.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:BindingTest"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
        <Page.Resources>
            <local:C x:Key="A" D="12" S="this is a test"/>
        </Page.Resources>
    
        <StackPanel x:Name="stackPanel" Margin="40,40,40,40">
            <TextBox x:Name="text1" Text="{Binding S, Source={StaticResource A}}" IsEnabled="False"/>
            <TextBox x:Name="text2" Text="{Binding D, Source={StaticResource A}}" IsEnabled="False"/>
        </StackPanel>
    </Page>
    

    This works fine in the design preview of Visual Studio (the values "this is a test" and "12" are displayed in the two text boxes).
    But when I execute the application, the text boxes are empty.

    If this is relevant, here is my implementation of class C:

    public ref class C sealed : INotifyPropertyChanged
    {
    private:
    	String^ _S;
    	double _D;
    public:
    	property String^ S {
    		String^ get() { return _S; }
    		void set(String^ _S) {
    			this->_S = _S;
    			PropertyChanged(this, ref new PropertyChangedEventArgs("S"));
    		}
    	}
    
    	property double D {
    		double get() { return _D; }
    		void set(double _D) {
    			this->_D = _D;
    			PropertyChanged(this, ref new PropertyChangedEventArgs("D"));
    		}
    	}
    
    	virtual event PropertyChangedEventHandler^ PropertyChanged;
    };

    Saturday, August 30, 2014 11:06 AM

All replies

  • Can you provide a minimal repro project that demonstrates the problem?

    It seems to work fine in the sample I just hooked up. I get "this is a test" and "12" in the TextBoxes both in the designer and when running.

    --Rob

    Wednesday, September 03, 2014 12:41 AM
    Owner
  • Here is a minimal project that produces the described error:

    http://1drv.ms/1uCPjkM

    PS: I could not figure out how to upload directly to this page

    Friday, September 05, 2014 6:06 PM