How can I set a stack panel's border color programmatically in C++ in WinUI3? - c++

I am working on a project using WinUI 3 in C++, and I want to change the border color of a XAML control(e.g. stackpanel) according to some condition. I have tried search it online, but most of answers are in c#, and some in C++ I have tried but got no luck.
For example: ("StackPanel" is defined in the xaml )
StackPanel().BorderBrush(SolidColorBrush(ColorHelper::FromArgb(255, 255, 255, 255)));
Then the error would come up:
no instance of overloaded function matches the argument list
argument types are: (winrt::Windows::UI::Xaml::Media::SolidColorBrush)
object type is: winrt::Microsoft::UI::Xaml::Controls::StackPanel
And another one I tried in .cpp file:
StackPanel().BorderBrushProperty(SolidColorBrush(Colors::Black()));
the error is:
too many arguments in function call.
Why are these errors happening?
Could anyone help me on this? Or any suggestions?
Sample code would be great!
PS : I am still very new to WinUI 3 especially in C++ (there are not so much study material for C++)
I would be grateful for any help.

From what I'm seeing the actual error (as best as i can replicate what you're doing) is
Severity Code Description Project File Line Suppression State
Error C2664 'void Windows::UI::Xaml::Controls::StackPanel::BorderBrush::set(Windows::UI::Xaml::Media::Brush ^)': cannot convert argument 1 from 'Windows::UI::Xaml::Media::SolidColorBrush' to 'Windows::UI::Xaml::Media::Brush ^' App1 c:\repos\App1\MainPage.xaml.cpp 29
If you create your brush like this auto brush = ref new SolidColorBrush(...);
And pass it to the stackpanel like this stackpanel->BorderBrush = brush;
Your error should go away.
Obviously how you are getting your stack panel might be different from how i did, but the point is you should be able to just set it to the value as long as you have the value in the correct form a ref new object in this case, it would seem.

Related

Using map function to map to user options to specific function

I am new to C++ and need some help with the following:
If i have no namespace this works fine as soon as i have this i get a error :
(active) E0109 expression preceding parentheses of apparent call must have (pointer-to-)
I am attaching a solution where i have implemented this code to show the error.
What i am tryng to achive is to use this map to call my menu options a user can select, it has a header file as well as the cpp implemtation file in it.
I have attached the source code with the error showing when trying to compile this.
I would greatly appreciate some help - sample attached done in visual studio Sample Code
https://www.dropbox.com/s/j5nkxabjah313wz/SampleMenu.zip?dl=0

glBindTexture - returns argument error

I am working on augmented reality project. So the user should use the Webcam, and to see the captured video with a cube drawn on that frame.
And this is where I get stuck , when I try to use glBindTexture(GL_TEXTURE_2D,texture_background) method, I get error:
(
ArgumentError: argument 2: : wrong type
GLUT Display callback with (),{} failed: returning None argument 2: : wrong type
)
I am completely stuck, have no idea what to do . The project is done in Python 2.7 , am using opencv and PyOpenGl 3.1.0.
You can find code on this link :click here
Thanks in advance.
Interesting error! So I played around with your source code (by the way in the future you should probably just add the code directly to your question instead of as a separate link), and the issue is actually just one of variable scope, not glut or opengl usage. The problem is your texture_background variable does not exist within the scope of the _draw_scene() function. To verify this, simply try calling print texture_background in your _draw_scene() function and you will find it returns None rather than the desired integer texture identifier.
The simple hack-y solution is to just call global texture_background before using it within your _handle_input() function. You will also need to define texture_background = None in the main scope of your program (underneath your ##FOR CUBE FROM OPENGL comment). The same global comment applies for x_axis and z_axis.
That being said, that solution is not really that great. The rigid structure required by GLUT with all of these predefined glut* functions makes it hard to structure code the way you might want to in terms of initializing your app. I would suggest, if you are not forced to use GLUT, to use a more flexible alternative, such as pygame, pysdl2 or pyqt, to create your context instead.

Declaring a new point using Emgu CV C++

Hi I can't seem to be able to even declare a point in Emgu CV currently. I'm trying to declare a new point so that I can use that point as the center of a rectangle which I will show on each frame of a video feed so that the user can see the Region of Interest. In my header file I have
Emgu::CV::Point2D<int,int>^Center;
and in my Source file I have
Center = gcnew Emgu::CV::Point2D<int,int>(120, 160);
The error that I'm getting is
5>c:\users\admin\desktop\swir source code\hyperspectral\baotfis\BAOTFISInterface.h(88): error C2039: 'Point2D' : is not a member of 'Emgu::CV'
which confuses me because how is it NOT a member of Emgu::CV?
Am I missing a namespace or am I just declaring it wrong? I'm using Microsoft Visual Studio 2010 Express. Any and all help is greatly appreciated thank you very much.
According to the Point2D documentation, Point2D only takes 1 template argument for the datatype of the point. You want:
Point2D<int>
Also, get rid of that '^' character - why is that even there?

Qt ActiveX dynamicCall: bad parameter count

I am trying to use an ActiveX control in my program.
QAxWidget* mAX = new QAxWidget();
mAX->setControl("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}");
I know that there is a function:
put_ChannelType(long newValue)
But when I try to execute it:
mAX->dynamicCall("put_ChannelType(long)",2);
mAX->dynamicCall("put_ChannelType(int)",2);
mAX->dynamicCall("put_ChannelType(long)",QVariant(2));
mAX->dynamicCall("put_ChannelType(int)",QVariant(2));
I get:
QAxBase: Error calling IDispatch member put_ChannelType: Bad parameter count
Any idea what is going wrong ?
EDIT:
Weird thing is if I call
mAX->dynamicCall("put_ChannelType()");
I do not get any error message...
EDIT 2:
This also fails (as Constantin suggested)
QList<QVariant> varlist;
varlist << (int)1;
mAX->dynamicCall("put_ChannelType(int)",varlist);
Got this solved using the generateDocumentation() function.
I was using this ActiveX control in another application, but an MFC one.
It seems the function names I was referring to (which were in a machine generated IDispatch wrapper class created by VS) were not the same as the ones Qt listed.
i.e. put_ChannelType is actually SetChannelType...
Maybe this is just a version issue ?
Anyways, important part is knowing that generateDocumentation() can list you all the functions you can call with dynamicCall.
Is it OK?
mAX->dynamicCall("put_ChannelType(const QVariant &)", (long)2);

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}