Hello,
had to change my question.
I want to bind the background of a stackpanel within a ListView's DataTemplate to a collection.
Then i want to be able to change the color by a double click.
It shall be an indicator, if it's activated or not as follows (white vertical line):
Obviously i can't find the right background data type for the runtime class (unresolved type declaration; doesn't work with string) and do i have to access the item's control on a click or do i have to change the collection and reload it?
My double click:
void winrt::App1::implementation::MainPage::ListViewTest_ItemClick(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::Controls::ItemClickEventArgs const& e)
{
static double DoubleClickTimeMS = GetDoubleClickTime();
static double LastTimeStamp = 0;
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - DoubleClickTimeMS <= LastTimeStamp)
{
// On double click
}
LastTimeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
For Reviewing (6.7.22):
Hey,
I've tried the following example for a converter: https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.data.ivalueconverter?view=winrt-22621
But i get a view errors by adding it as listview ressource (local:ColorConverter) in MainPage.xaml:
I've also changed the property to boolean and i don't really know, if the following will work correctly for changing the value by double clicking from the click event (i couldn't really figure out where in the view models i could do it properly so i just tested it with String in a TextBlock and it's stored but can't be displayed; can't be right, it's because of the binding?!):
e.ClickedItem().as<AppProcess>().get()->Activated(true);
I'm just using the example from Castorix (http://pastebin.fr/105048) combinded with a mainviewmodel of the bookstore example: https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/binding-property
My converter:
ColorConverter.idl
namespace App1
{
runtimeclass ColorConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
ColorConverter();
}
}
ColorConverter.h
#pragma once
#include "ColorConverter.g.h"
namespace winrt::App1::implementation
{
struct ColorConverter : ColorConverterT<ColorConverter>
{
ColorConverter() = default;
winrt::Windows::Foundation::IInspectable Convert(winrt::Windows::Foundation::IInspectable const& value, winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, winrt::Windows::Foundation::IInspectable const& parameter, hstring const& language);
winrt::Windows::Foundation::IInspectable ConvertBack(winrt::Windows::Foundation::IInspectable const& value, winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, winrt::Windows::Foundation::IInspectable const& parameter, hstring const& language);
};
}
namespace winrt::App1::factory_implementation
{
struct ColorConverter : ColorConverterT<ColorConverter, implementation::ColorConverter>
{
};
}
ColorConverter.cpp (I guess bool has to be edited because of IInspectable later)
#include "pch.h"
#include "ColorConverter.h"
#include "ColorConverter.g.cpp"
using namespace winrt;
using namespace Windows::UI::Xaml;
namespace winrt::App1::implementation
{
winrt::Windows::Foundation::IInspectable ColorConverter::Convert(winrt::Windows::Foundation::IInspectable const& value, winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, winrt::Windows::Foundation::IInspectable const& parameter, hstring const& language)
{
if ((bool)value) { return box_value(Microsoft::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::DarkGray() }); }
else { return box_value(Microsoft::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Green() }); }
}
winrt::Windows::Foundation::IInspectable ColorConverter::ConvertBack(winrt::Windows::Foundation::IInspectable const& value, winrt::Windows::UI::Xaml::Interop::TypeName const& targetType, winrt::Windows::Foundation::IInspectable const& parameter, hstring const& language)
{
throw hresult_not_implemented();
}
}
Update (7.7.22):
The errors are gone, i've added the converter's header in the pch.h. (https://stackoverflow.com/questions/44031687/vc-converter-is-not-a-member-of-namespace)
Now i have a hresult error with x:bind. May be i have to use a function?!