代码之家  ›  专栏  ›  技术社区  ›  justanotherxl

如何使用C++CX中的Calendarview::SetDensityColor方法

  •  0
  • justanotherxl  · 技术社区  · 8 年前

    下面是我尝试调用的方法:

    https://msdn.microsoft.com/en-us/library/windows/apps/dn890067.aspx

    所以我创建了一个平台::Collections::Vector并填充它,非常简单,对吗?

    Platform::Collections::Vector<Windows::UI::Color>^ dayColors = ref new Platform::Collections::Vector<Windows::UI::Color>();
    dayColors->Append(Windows::UI::Colors::Green);
    myCalendarView->SetDensityColors(dayColors);
    

    然而,我得到了这个编译错误,我一直无法解决:

    错误C2678:二进制“==”:未找到接受类型为“常量Windows::UI::Color”的左手操作数的运算符(或没有可接受的转换)

    我该怎么解决这个问题?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Sunteen Wu    8 年前

    错误C2678:二进制“==”:未找到接受类型为“常量Windows::UI::Color”的左手操作数的运算符(或没有可接受的转换)

    这个错误实际上是由代码行引发的 Platform::Collections::Vector<Windows::UI::Color>^ dayColors .根据向量中的值类型 Collections (C++/CX) 文件:

    对于非标量值类型,如Windows::Foundation::DateTime,或对于自定义比较,例如,objA->UniqueID==objB->UniqueIDyou必须提供自定义函数对象。

    Windows::UI::Color is结构类型可能包含自定义比较,因此需要自定义函数对象。

    添加如下自定义结构将解决您的问题:

    struct MyEqual : public std::binary_function<const Windows::UI::Color, const Windows::UI::Color, bool>
    {
        bool operator()(const Windows::UI::Color& _Left, const Windows::UI::Color& _Right) const
        {
            return _Left.A == _Right.A;
        };
    };
    
    void CCalendarView2::MainPage::CalendarView_CalendarViewDayItemChanging(Windows::UI::Xaml::Controls::CalendarView^ sender, Windows::UI::Xaml::Controls::CalendarViewDayItemChangingEventArgs^ args)
    {
        Platform::Collections::Vector<Windows::UI::Color, MyEqual>^ dayColors = ref new Platform::Collections::Vector<Windows::UI::Color,MyEqual>();
        dayColors->Append(Windows::UI::Colors::Green); 
        args->Item->SetDensityColors(dayColors);
    }