如何在 C++ 中以编程方式设置堆栈面板的边框颜色在WinUI3中?
我正在使用 C++ 中的 WinUI 3 开发一个项目,我想根据某些条件更改 XAML 控件(例如 stackpanel)的边框颜色。我尝试过在线搜索,但大多数答案都是用 C# 编写的,还有一些用 C++ 编写的,我尝试过但没有成功。
例如:(“StackPanel”在 xaml 中定义)
StackPanel().BorderBrush(SolidColorBrush(ColorHelper::FromArgb(255, 255, 255, 255)));
然后会出现错误:
没有重载函数的实例与参数列表匹配
参数类型为:(winrt::Windows::UI::Xaml::Media::SolidColorBrush)
对象类型为:winrt::Microsoft::UI::Xaml::Controls::StackPanel
我在 .cpp 文件中尝试过另一个对象类型:
StackPanel().BorderBrushProperty(SolidColorBrush(Colors::Black()));
错误是:
函数调用中的参数过多。
为什么会发生这些错误?
有人能帮我解决这个问题吗?或者有什么建议吗?
示例代码会很棒!
PS:我对 WinUI 3 还是很陌生,尤其是在 C++ 方面(没有太多 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从我所看到的实际错误(尽可能复制您正在做的事情)是
如果您像这样创建画笔
auto Brush = ref new SolidColorBrush(...);
< br>并将其传递给 stackpanel,如下所示
stackpanel->BorderBrush = Brush;
你的错误应该消失。
显然,您获取堆栈面板的方式可能与我的方式不同,但重点是,只要您拥有正确形式的值,您就应该能够将其设置为值
ref new object 在这种情况下,看起来。
From what I'm seeing the actual error (as best as i can replicate what you're doing) is
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.