Ric*_*nks 9 c++ xaml binding microsoft-metro c++-cx
我必须遗漏一些明显的东西,但我不确定是什么.
我已经创建了一个空白的C++ metro应用程序,我刚刚添加了一个我将在我的UI中绑定的模型,但是我遇到了一系列相关的编译错误xamltypeinfo.g.cpp,我不确定我错过了什么.
我的头文件如下所示:
#pragma once
#include "pch.h"
#include "MyColor.h"
using namespace Platform;
namespace CppDataBinding
{
[Windows::UI::Xaml::Data::Bindable]
public ref class MyColor sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
{
public:
MyColor();
~MyColor();
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
property Platform::String^ RedValue
{
Platform::String^ get()
{
return _redValue;
}
void set(Platform::String^ value)
{
_redValue = value;
RaisePropertyChanged("RedValue");
}
}
protected:
void RaisePropertyChanged(Platform::String^ name);
private:
Platform::String^ _redValue;
};
}
Run Code Online (Sandbox Code Playgroud)
和我的cpp文件看起来像这样:
#include "pch.h"
#include "MyColor.h"
using namespace CppDataBinding;
MyColor::MyColor()
{
}
MyColor::~MyColor()
{
}
void MyColor::RaisePropertyChanged(Platform::String^ name)
{
if (PropertyChanged != nullptr)
{
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(name));
}
}
Run Code Online (Sandbox Code Playgroud)
没有什么太棘手,但是当我编译时,我得到错误,xamltypeinfo.g.cpp表明MyColor没有定义CppDataBinding.
相关的生成代码如下所示:
if (typeName == "CppDataBinding.MyColor")
{
userType = ref new XamlUserType(this, typeName, GetXamlTypeByName("Object"));
userType->Activator = ref new XamlTypeInfo::InfoProvider::Activator(
[]() -> Platform::Object^
{
return ref new CppDataBinding::MyColor();
});
userType->AddMemberName("RedValue", "CppDataBinding.MyColor.RedValue");
userType->SetIsBindable();
xamlType = userType;
}
Run Code Online (Sandbox Code Playgroud)
如果我Bindable从MyColor代码中删除属性编译.
有人能告诉我,我错过了一个令人眼花缭乱的明显事物,所以我可以给自己一个问题并解决问题吗?
Ric*_*nks 15
我做了一个小改动现在它的工作原理.
我补充道
#include "MyColor.h"
Run Code Online (Sandbox Code Playgroud)
到BlankPage.xaml.h文件,即使我还没有添加任何其他引用MyColor,它现在编译.
我想如果你做了一些东西[Bindable],标题必须包含在至少一个xaml页面中才能工作.在任何地方都未引用的可绑定类型会导致编译器错误.
| 归档时间: |
|
| 查看次数: |
2490 次 |
| 最近记录: |