C++ How to properly cast PropertyChangedEventArgs.newValue
As the OnPropertyChanged(DependencyPropertyChangedEventArgs& arg) arg.newValue is a const void pointer, and I don't know what type it is when the property is ForegroundProperty, I can't clone it and set it as a new foreground. How do I fix this:
Can the "GetType" sort of functions be leveraged in a future situations to find out what type the most derived class is, since the document is lacking in this front?
Code: Select all
if (e.prop == ForegroundProperty)
{
//Brush* brush = (Brush*)((Brush*)arg.newValue)->Clone().GetPtr();
ButtonControl->SetForeground((Brush*)arg.newValue);
}
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: C++ How to properly cast PropertyChangedEventArgs.newVal
Hi,
Foreground property is of type Brush, so you should be able to use its Clone method without problem:
Foreground property is of type Brush, so you should be able to use its Clone method without problem:
Code: Select all
if (e.prop == ForergroundProperty)
{
Brush* brush = static_cast<const Ptr<Brush>*>(args.newValue)->GetPtr();
Ptr<Brush> brushClone = NsStaticCast<Ptr<Brush> >(brush->Clone());
ButtonControl->SetForeground(brushClone.GetPtr());
}
Re: C++ How to properly cast PropertyChangedEventArgs.newVal
Both casts should work
Your problem was when doing the Clone(). As a new object is being created you need to store it in a Ptr<> to hold a strong reference.
The main reason we are using void* in newValue and oldValue is efficiency. We wanted to avoid boxing values in our first architecture. But right now, boxing is quite fast and we should probably reevaluate this decision.
Code: Select all
Brush* brush = static_cast<const Ptr<Brush>*>(args.newValue)->GetPtr();
Code: Select all
Brush* brush = static_cast<Brush*>(args.newValue);
The main reason we are using void* in newValue and oldValue is efficiency. We wanted to avoid boxing values in our first architecture. But right now, boxing is quite fast and we should probably reevaluate this decision.
Re: C++ How to properly cast PropertyChangedEventArgs.newVal
Works now, thank you!
Who is online
Users browsing this forum: Bing [Bot], ttermeer-reboundcg and 2 guests