Убирать связанные свойства - PullRequest
0 голосов
/ 13 января 2020

У меня есть свойство коллекции IVector, которое связано с элементом xaml.

using PlatformStringVector = Windows::Foundation::Collections::IVector<Platform::String^>^;

Член коллекции:

PlatformStringVector m_dataCollection = ref new Platform::Collections::Vector<Platform::String^>();

Свойство:

property PlatformStringVector DataCollection
{
  PlatformStringVector get() { return m_dataCollection; }
  void set(PlatformStringVector value) { SetProperty(m_dataCollection, value, "DataCollection");}
}

I пытаюсь очистить коллекцию от фоновой темы. Если я очищаю связанное свойство, я получаю ошибку от xaml, равную нулю.

DataCollection->Clear();

Но если очистка выполняется с помощью

m_dataCollection->Clear().

Все работает нормально.

В чем разница между Property Clear и управляемой данными clear?

/// <summary>Initializes the session asynchronous.</summary>
void App::InitSessionAsync()
{
    concurrency::create_task([this]
    {
        WaitForDevice();
    }).then([this](concurrency::task<void> task)
    {
        try
        {
            task.get();
        }
        catch (const Polytec::IO::CommunicationException & ex)
        {
            ..
        }

        AppData::ViewModel->DataCollection->Clear(); // This clear does not work.             
        //AppData::ViewModel->ClearCollection(); // It actually clears the data collection member. And this works

        auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
        rootFrame->Navigate(TypeName(MainPage::typeid), nullptr, ref new Animation::SuppressNavigationTransitionInfo);
    }, concurrency::task_continuation_context::use_current());
}
...