C2039 error on MyStackPanel->HorizontalAlignment= HorizontalAlignment::Center; - by Andrew7Webb

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 745947 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 6/1/2012 7:59:33 PM
Access Restriction Public

Description

I get a 
error C2039: 'Center' : is not a member of 'Windows::UI::Xaml::FrameworkElement::HorizontalAlignment'
for:  MyStackPanel->HorizontalAlignment= HorizontalAlignment::Center;

even though I have a "using namespace Windows::UI::Xaml;"
and the previous line compiles fine:
 MyStackPanel->HorizontalAlignment= Windows::UI::Xaml::HorizontalAlignment::Center;

Even stranger, the same line works fine in a function not part of the MainPage class:

void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
 MyStackPanel->HorizontalAlignment= Windows::UI::Xaml::HorizontalAlignment::Center;
 MyStackPanel->HorizontalAlignment=                    HorizontalAlignment::Center;
}

void notMemberFunction(NavigationEventArgs^ e)
{
 TextBlock^ dynTextBlock = ref new TextBlock(); 

 dynTextBlock->Text= "dynTextBlock created dynamically";
 dynTextBlock->HorizontalAlignment= Windows::UI::Xaml::HorizontalAlignment::Center;
   dynTextBlock->HorizontalAlignment=                    HorizontalAlignment::Center; 
}

This was tested with the Release Candidate 
Microsoft Visual Studio Professional 2012 RC
Version 11.0.50522.1 RCREL

Sign in to post a comment.
Posted by Andrew7Webb on 6/6/2012 at 5:03 AM
Now I see the crucial difference between the non-member and the member function was the availablility of the property in the base class of MainPage. Thank you.
Posted by Microsoft on 6/5/2012 at 3:54 PM
Hi,
    Thanks for reporting the issue. This is by design because the base class of MainPage contains a property of the same name 'HorizontalAlignment' and it is chosen.

    This can also be illustrated as follows:

namespace N {
    enum E {e};
}
using namespace N;

class Base {
public:
    struct E {};
};

class Derived : public Base {
    void f() {
        E::e; // The one from Base is used
    }
};

Xiang Fan
Visual C++ Team
Posted by Andrew7Webb on 6/5/2012 at 1:52 PM
Yes, the line above has the fullpath. But the bug is that

using namespace Windows::UI::Xaml;

is ignored.

See also:

http://charlespetzold.com/blog/2012/05/Programming-Windows-6th-Edition-for-the-CPlusPlus-Programmer.html
Posted by Microsoft on 6/4/2012 at 9:21 PM
Andrew,

If you use the full type name it should work:
MyStackPanel->HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Center;

-Tim Heuer, XAML
Posted by MS-Moderator01 on 6/1/2012 at 8:42 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)