HateDread
Topic Author
Posts: 74
Joined: 06 Feb 2020, 10:27

Noesis::TimeSpan has no properties?

05 Oct 2023, 13:48

Using Noesis::TimeSpan instead of the WPF/C# Timespan that works in my mock project, with the following binding
<MultiBinding StringFormat="{}+{0:00}:{1:00}:{2:00;00}" FallbackValue="+00:00:13">
    <Binding Path="HoveredTimeDifference.Hours" />
    <Binding Path="HoveredTimeDifference.Minutes" />
    <Binding Path="HoveredTimeDifference.Seconds" />
</MultiBinding>
It works in C#/Blend, but in C++ using Noesis::TimeSpan I get
Type 'TimeSpan' does not contain a property named 'Seconds'
Type 'TimeSpan' does not contain a property named 'Minutes'
Type 'TimeSpan' does not contain a property named 'Hours'
Is there a workaround/have I misunderstood something?

Thanks!
 
HateDread
Topic Author
Posts: 74
Joined: 06 Feb 2020, 10:27

Re: Noesis::TimeSpan has no properties?

05 Oct 2023, 14:10

Here is my workaround
#include "NsApp/NotifyPropertyChangedBase.h"
#include "NsCore/ReflectionImplement.h"
#include "NsGui/TimeSpan.h"

class ExposedTimeSpan
{
public:
	ExposedTimeSpan() = default;
	ExposedTimeSpan(float seconds)
		: timeSpan_(seconds) {}

	~ExposedTimeSpan() = default;

	ExposedTimeSpan(const ExposedTimeSpan&) = default;
	ExposedTimeSpan(ExposedTimeSpan&&) = default;

	ExposedTimeSpan& operator=(const ExposedTimeSpan&) = default;
	ExposedTimeSpan& operator=(ExposedTimeSpan&&) = default;

	/// Returns a string that represents the current object
	Noesis::String ToString() const {
		return Noesis::String("ExposedTimeSpan");
	}

	int GetSeconds() const {
		return timeSpan_.GetSeconds();
	}

	int GetMinutes() const {
		return timeSpan_.GetMinutes();
	}

	int GetHours() const {
		return timeSpan_.GetHours();
	}

	double GetTimeInSeconds() const {
		return timeSpan_.GetTimeInSeconds();
	}

	bool operator==(const ExposedTimeSpan& rhs) const {
		return timeSpan_.GetTicks() == rhs.timeSpan_.GetTicks();
	}

	NS_IMPLEMENT_INLINE_REFLECTION(ExposedTimeSpan, Noesis::NoParent, "ExposedTimeSpan")
	{
		NsProp("Seconds", &ExposedTimeSpan::GetSeconds);
		NsProp("Minutes", &ExposedTimeSpan::GetMinutes);
		NsProp("Hours", &ExposedTimeSpan::GetHours);
	}

private:
	Noesis::TimeSpan timeSpan_;
};
I can now use the same XAML with Blend and Noesis C++. Not sure of the implications but for my use-case it seems to be enough!
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Noesis::TimeSpan has no properties?

05 Oct 2023, 14:21

This was fixed in #2657. Could you try the latest 3.2.2 to verify?

Who is online

Users browsing this forum: No registered users and 3 guests