locked
public access to XAMAL elements in a user control

    Question

  • I have some user controls that have a  child TextBox member. With C++ do I have to explicitly define an access property for this member or is there a way to decorate the XAML to create a default access property?
    Wednesday, October 3, 2012 2:37 AM

Answers

  • Thanks for the reply.

    Update: It was a stupid mistake on my part. I've been coding in C# for too long ;-)

    I used to do a lot of C++ development years ago and I'm just now getting back into working with the language again. My problem was that I was not including the header file for the user control, so none of my customization to the control were available.

    Thanks again

    Thursday, October 4, 2012 7:50 PM

All replies

  • Hi,

    I cannot reproduce this issue. Maybe you can try this codes.

    <UserControl
        x:Class="SDKSample.UserAndCustomControls.BasicUserControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:SDKSample.UserAndCustomControls"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300"
        d:DesignWidth="400">
    
        <Grid>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Your Name: " FontSize="26.667" Margin="0,0,20,0" />
                    <TextBox x:Name="NameInput" Width="300" />
                </StackPanel>
                <Button Content="Click Me" Click="ClickMeButtonClicked"/>
                <TextBlock FontSize="53" x:Name="OutputText" />
            </StackPanel>
        </Grid>
    </UserControl>

    // in head file
    #pragma once
    
    #include "pch.h"
    #include "BasicUserControl.g.h"
    
    namespace SDKSample
    {
        namespace UserAndCustomControls
        {
        	public ref class BasicUserControl sealed
        	{
        	public:
        		BasicUserControl();
    			property Windows::UI::Xaml::Controls::TextBox^ Inputtbx
    			{
    				Windows::UI::Xaml::Controls::TextBox^ get(){return input;}
    				
    			}
        	private:
    			Windows::UI::Xaml::Controls::TextBox^ input;
        		void ClickMeButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
        	};
        }
    }
    
    
    // In cpp file
    BasicUserControl::BasicUserControl()
    {
    	InitializeComponent();
    	this->input=this->NameInput;
    }
    
    
    void SDKSample::UserAndCustomControls::BasicUserControl::ClickMeButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	OutputText->Text = "Hello " + NameInput->Text;
    }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, October 4, 2012 6:07 AM
  • Thanks for the reply.

    Update: It was a stupid mistake on my part. I've been coding in C# for too long ;-)

    I used to do a lot of C++ development years ago and I'm just now getting back into working with the language again. My problem was that I was not including the header file for the user control, so none of my customization to the control were available.

    Thanks again

    Thursday, October 4, 2012 7:50 PM