Я пытаюсь сделать проект на c ++ / winrt, чтобы узнать немного больше о разработке на c ++ и windows. Используемая мной версия c ++ / winrt: 2.0.200117.5
У меня есть следующие классы который я хочу использовать для привязки IObservableVector к пользовательскому интерфейсу xaml
BrushSizeModel .idl
namespace DrawingCanvas
{
[bindable]
[default_interface]
runtimeclass BrushSizeModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
BrushSizeModel();
BrushSizeModel(Single width, Single height);
Single Width;
Single Height;
}
}
.h
#pragma once
#include "BrushSizeModel.g.h"
namespace winrt::DrawingCanvas::implementation
{
struct BrushSizeModel : BrushSizeModelT<BrushSizeModel>
{
BrushSizeModel() = default;
BrushSizeModel(float width, float height);
float Width();
void Width(float value);
float Height();
void Height(float value);
winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& value);
void PropertyChanged(winrt::event_token const& token);
private:
float m_width;
float m_height;
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
};
}
namespace winrt::DrawingCanvas::factory_implementation
{
struct BrushSizeModel : BrushSizeModelT<BrushSizeModel, implementation::BrushSizeModel>
{
};
}
. cpp
#include "pch.h"
#include "BrushSizeModel.h"
#if __has_include("BrushSizeModel.g.cpp")
#include "BrushSizeModel.g.cpp"
#endif
namespace winrt::DrawingCanvas::implementation
{
BrushSizeModel::BrushSizeModel(float width, float height)
:m_width(width),
m_height(height)
{
}
float BrushSizeModel::Width()
{
return m_width;
}
void BrushSizeModel::Width(float value)
{
m_width = value;
}
float BrushSizeModel::Height()
{
return m_height;
}
void BrushSizeModel::Height(float value)
{
m_height = value;
}
winrt::event_token BrushSizeModel::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
{
return m_propertyChanged.add(handler);
}
void BrushSizeModel::PropertyChanged(winrt::event_token const& token)
{
m_propertyChanged.remove(token);
}
}
BrushDataModel .id
import "BrushSizeModel.idl";
namespace DrawingCanvas
{
[bindable]
[default_interface]
runtimeclass BrushDataModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
BrushDataModel();
BrushDataModel(
String id,
String name,
BrushSizeModel size,
Windows.UI.Input.Inking.PenTipShape penTipShape
);
String Id;
String Name;
BrushSizeModel Size;
Windows.UI.Input.Inking.PenTipShape PenTipShape;
}
}
.h
#pragma once
#include "BrushDataModel.g.h"
#include "BrushSizeModel.g.h"
namespace winrt::DrawingCanvas::implementation
{
struct BrushDataModel : BrushDataModelT<BrushDataModel>
{
BrushDataModel();
BrushDataModel(
hstring id,
hstring name,
BrushSizeModel size,
Windows::UI::Input::Inking::PenTipShape penTipShape
);
hstring Id();
void Id(hstring value);
hstring Name();
void Name(hstring value);
BrushSizeModel Size();
void Size(BrushSizeModel value);
Windows::UI::Input::Inking::PenTipShape PenTipShape();
void PenTipShape(Windows::UI::Input::Inking::PenTipShape value);
winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& value);
void PropertyChanged(winrt::event_token const& token);
private:
static Windows::UI::Xaml::DependencyProperty m_IsMovableProperty;
hstring m_id;
hstring m_name;
BrushSizeModel m_size;
Windows::UI::Input::Inking::PenTipShape m_penTipShape;
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
};
}
namespace winrt::DrawingCanvas::factory_implementation
{
struct BrushDataModel : BrushDataModelT<BrushDataModel, implementation::BrushDataModel>
{
};
}
. cpp
#include "pch.h"
#include "BrushDataModel.h"
#if __has_include("BrushDataModel.g.cpp")
#include "BrushDataModel.g.cpp"
#endif
namespace winrt::DrawingCanvas::implementation
{
BrushDataModel::BrushDataModel()
: m_id(L"NO_ID"),
m_name(L"NO_NAME"),
m_size(BrushSizeModel()),
m_penTipShape(Windows::UI::Input::Inking::PenTipShape::Circle)
{
}
BrushDataModel::BrushDataModel(hstring id, hstring name, BrushSizeModel size, Windows::UI::Input::Inking::PenTipShape penTipShape)
: m_id(id),
m_name(name),
m_size(size),
m_penTipShape(penTipShape)
{
}
hstring BrushDataModel::Id()
{
return m_id;
}
void BrushDataModel::Id(hstring value)
{
m_id = value;
}
hstring BrushDataModel::Name()
{
return m_name;
}
void BrushDataModel::Name(hstring value)
{
m_name = value;
}
BrushSizeModel BrushDataModel::Size()
{
return m_size;
}
void BrushDataModel::Size(BrushSizeModel value)
{
m_size = value;
}
Windows::UI::Input::Inking::PenTipShape BrushDataModel::PenTipShape()
{
return m_penTipShape;
}
void BrushDataModel::PenTipShape(Windows::UI::Input::Inking::PenTipShape value)
{
m_penTipShape = value;
}
winrt::event_token BrushDataModel::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
{
return m_propertyChanged.add(handler);
}
void BrushDataModel::PropertyChanged(winrt::event_token const& token)
{
m_propertyChanged.remove(token);
}
}
BrushCreatorViewModel .idl
import "BrushDataModel.idl";
namespace DrawingCanvas
{
[bindable]
[default_interface]
runtimeclass BrushCreatorViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
BrushCreatorViewModel();
Windows.Foundation.Collections.IObservableVector<BrushDataModel> VmFilteredBrushes{ get; };
String VmFilter;
}
}
.h
#pragma once
#include "BrushCreatorViewModel.g.h"
#include "BrushDataModel.h"
#include <vector>
namespace winrt::DrawingCanvas::implementation
{
struct BrushCreatorViewModel : BrushCreatorViewModelT<BrushCreatorViewModel>
{
BrushCreatorViewModel();
winrt::event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& value);
void PropertyChanged(winrt::event_token const& token);
Windows::Foundation::Collections::IObservableVector<BrushDataModel> VmFilteredBrushes();
hstring VmFilter();
void VmFilter(hstring value);
private:
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
Windows::Foundation::Collections::IObservableVector<BrushDataModel> m_filteredBrushes;
std::vector<BrushDataModel> m_allBrushesList;
hstring m_filter;
private:
void ApplyFilter();
};
}
namespace winrt::DrawingCanvas::factory_implementation
{
struct BrushCreatorViewModel : BrushCreatorViewModelT<BrushCreatorViewModel, implementation::BrushCreatorViewModel>
{
};
}
. cpp
#include "pch.h"
#include "BrushCreatorViewModel.h"
#if __has_include("BrushCreatorViewModel.g.cpp")
#include "BrushCreatorViewModel.g.cpp"
#endif
namespace winrt::DrawingCanvas::implementation
{
BrushCreatorViewModel::BrushCreatorViewModel()
:m_allBrushesList(),
m_filter(L"")
{
m_filteredBrushes = winrt::single_threaded_observable_vector<BrushDataModel>();
}
winrt::event_token BrushCreatorViewModel::PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler)
{
return m_propertyChanged.add(handler);
}
void BrushCreatorViewModel::PropertyChanged(winrt::event_token const& token)
{
m_propertyChanged.remove(token);
}
Windows::Foundation::Collections::IObservableVector<BrushDataModel> BrushCreatorViewModel::VmFilteredBrushes()
{
return m_filteredBrushes;
}
hstring BrushCreatorViewModel::VmFilter()
{
return m_filter;
}
void BrushCreatorViewModel::VmFilter(hstring value)
{
m_filter = value;
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"VmFilter" });
}
void BrushCreatorViewModel::ApplyFilter()
{
}
}
При компиляции я получаю следующую ошибку, которую я попытался в Google, чтобы увидеть, что я Я упустил из того, что я понял, мои классы должны в конечном итоге происходить из типа winrt, но этого нет нигде в онлайн-примерах. Кто-нибудь может помочь, если затравить, если есть проблема в моем коде?
1>Validating metadata file Debug\Merged\DrawingCanvas.winmd.
1>BrushCreatorView.cpp
1>BrushCreatorViewModel.cpp
1>BrushDataModel.cpp
1>BrushSizeModel.cpp
1>App.cpp
1>MainPage.cpp
1>XamlTypeInfo.Impl.g.cpp
1>D:\Workspace\Organiztions\home\visual-cpp\DrawingCanvas\DrawingCanvas\Generated Files\winrt\impl\Windows.Foundation.Collections.1.h(90,29): error C2338: T must be WinRT type. (compiling source file BrushCreatorViewModel.cpp)
1>D:\Workspace\Organiztions\home\visual-cpp\DrawingCanvas\DrawingCanvas\BrushCreatorViewModel.h(26): message : see reference to class template instantiation 'winrt::Windows::Foundation::Collections::IObservableVector<winrt::DrawingCanvas::implementation::BrushDataModel>' being compiled (compiling source file BrushCreatorViewModel.cpp)
1>Done building project "DrawingCanvas.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========