Dependency property that expects list of integers in c++
Posted: 26 Feb 2020, 11:23
I want to be able to assign a list of integers to a dependency property, as done here:
This works perfectly fine in blend using C# with this sample:
However, I have trouble converting this to C++ because of the following reasons, please correct me if I'm wrong in one of the following statements:
I'm a bit stuck on this one, any help is appriciated!
Code: Select all
<Button Content="TEST" ui:KeyTriggerExtension.Key="179, 168, 23"/>Code: Select all
public class KeyTriggerExtension
{
public static readonly DependencyProperty Key = DependencyProperty.RegisterAttached("Key", typeof(List<int>), typeof(KeyTriggerExtension), new PropertyMetadata(default(List<int>)));
public static void SetKey(DependencyObject element, List<int> value)
{
element.SetValue(Key, value);
}
public static List<int> GetKey(DependencyObject element)
{
return (List<int>)element.GetValue(Key);
}- I can't use a generic type of std list/vector with Noesis (in C# I use a generic list)
- I can use Collection or Observable collection, but the type needs to be atleast a BaseComponent
- I can Box/Unbox the integers if I use a list of BaseComponents
Code: Select all
class TGCNoesisKeyTriggerExtension : public Noesis::DependencyObject
{
public:
void SetKey(Noesis::ObservableCollection<Noesis::BaseComponent>* pValue);
Noesis::ObservableCollection<Noesis::BaseComponent>* GetKey();
static void KeyChanged(Noesis::DependencyObject* d, const Noesis::DependencyPropertyChangedEventArgs& e);
//
static const Noesis::DependencyProperty* Key;
private:
NS_IMPLEMENT_INLINE_REFLECTION(TGCNoesisKeyTriggerExtension, Noesis::DependencyObject)
{
NsMeta<Noesis::TypeId>("UI.KeyTriggerExtension");
const Noesis::TypeClass* type = Noesis::TypeOf<SelfClass>();
Noesis::UIElementData* data = NsMeta<Noesis::UIElementData>(type);
data->RegisterProperty<Noesis::Ptr<Noesis::ObservableCollection<Noesis::BaseComponent>>>(Key, "Key", Noesis::FrameworkPropertyMetadata::Create(Noesis::Ptr<Noesis::ObservableCollection<Noesis::BaseComponent>>(), KeyChanged));
}
};
////////////////////////////////////////////////////
const Noesis::DependencyProperty* TGCNoesisKeyTriggerExtension::Key;
void TGCNoesisKeyTriggerExtension::SetKey(Noesis::ObservableCollection<Noesis::BaseComponent>* pValue)
{
SetValue<Noesis::Ptr<Noesis::ObservableCollection<Noesis::BaseComponent>>>(Key, pValue);
}
Noesis::ObservableCollection<Noesis::BaseComponent>* TGCNoesisKeyTriggerExtension::GetKey()
{
return GetValue<Noesis::Ptr<Noesis::ObservableCollection<Noesis::BaseComponent>>>(Key).GetPtr();
}
void TGCNoesisKeyTriggerExtension::KeyChanged(Noesis::DependencyObject* d, const Noesis::DependencyPropertyChangedEventArgs& e)
{
}