confused about ObservableCollection
Hi,
I want to parse a string to an array, for some reason I need to use ObaservableCollection<NsString>,
but I got an error
Error C2555 'Noesis::ObservableCollection<NsString>::Get': overriding virtual function return type differs and is not covariant from 'Noesis::Collection::Get'
I find that the IList::Get(uint32_t InIndex) return a BaseComponent* , but NsStrin is not a BaseComponet, some advices?
I want to parse a string to an array, for some reason I need to use ObaservableCollection<NsString>,
but I got an error
Error C2555 'Noesis::ObservableCollection<NsString>::Get': overriding virtual function return type differs and is not covariant from 'Noesis::Collection::Get'
I find that the IList::Get(uint32_t InIndex) return a BaseComponent* , but NsStrin is not a BaseComponet, some advices?
Re: confused about ObaervableCollection
And another , about ObservableCollection
Code: Select all
//WPF version RichTextblock
namespace GameGUI
{
public class RichTextBlock : TextBlock
{
public ObservableCollection<Inline> InlineList
{
get { return (ObservableCollection<Inline>)GetValue(InlineListProperty); }
set { SetValue(InlineListProperty, value); }
}
public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), typeof(RichTextBlock),
new UIPropertyMetadata(null, OnPropertyChanged));
private static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
RichTextBlock rtb = (RichTextBlock)sender;
if(rtb != null && e.OldValue != e.NewValue)
{
ObservableCollection<Inline> RichTextToAdd = new ObservableCollection<Inline>();
rtb.Inlines.Clear();
rtb.Inlines.AddRange(rtb.InlineList);
}
}
}
}
Code: Select all
//C++
const DependencyProperty* RichTextBlock::InlineListProperty;
RichTextBlock::RichTextBlock()
{
}
NS_IMPLEMENT_REFLECTION(RichTextBlock)
{
NsMeta<TypeId>("GameGUI.RichTextBlock");
Ptr<UIElementData> UIData = NsMeta<UIElementData>(TypeOf<SelfClass>());
UIData.RegisterProperty<ObservableCollection<Inline>>(InlineListProperty, "Inline",
FrameworkPropertyMetadata::Create(NULL, FrameworkOptions_None, &OnPropertyChanged));
}
Noesis::ObservableCollection<Noesis::Inline> GameGUI::RichTextBlock::GetInlineList() const
{
return DependencyObject::GetValue<ObservableCollection<Inline>>(InlineListProperty);
}
void GameGUI::RichTextBlock::SetInlineList(const ObservableCollection<Inline>& InlineList)
{
DependencyObject::SetValue<ObservableCollection<Inline>>(InlineListProperty, InlineList);
}
void GameGUI::RichTextBlock::OnPropertyChanged(DependencyObject* sender, const DependencyPropertyChangedEventArgs& e)
{
RichTextBlock* rtb = (RichTextBlock*)sender;
if (rtb != nullptr && e.newValue != e.oldValue)
{
rtb->GetInlines()->Clear();
//no AddRange?
rtb->GetInlines().AddRange(rtb->GetInlineList());
}
}
Re: confused about ObaervableCollection
Yesterday I got similar error, maybe same. From your code, I don't see problem, I never used InLine, but in my problem was I had included header file with class declaration and after change it in to empty declaration "class something;" it throw me this error, because I used object from header in NS_IMPLEMENT_INLINE_REFLECTION, then I divided it in to *.h NS_DECLARE_REFLECTION and in *.cpp I included somethingClass.h and add NS_IMPLEMENT_REFLECTION(). After that error gone. I hope you get some idea where is your problem.Hi,
I want to parse a string to an array, for some reason I need to use ObaservableCollection<NsString>,
but I got an error
Error C2555 'Noesis::ObservableCollection<NsString>::Get': overriding virtual function return type differs and is not covariant from 'Noesis::Collection::Get'
I find that the IList::Get(uint32_t InIndex) return a BaseComponent* , but NsStrin is not a BaseComponet, some advices?
Re: confused about ObaervableCollection
Hi,Yesterday I got similar error, maybe same. From your code, I don't see problem, I never used InLine, but in my problem was I had included header file with class declaration and after change it in to empty declaration "class something;" it throw me this error, because I used object from header in NS_IMPLEMENT_INLINE_REFLECTION, then I divided it in to *.h NS_DECLARE_REFLECTION and in *.cpp I included somethingClass.h and add NS_IMPLEMENT_REFLECTION(). After that error gone. I hope you get some idea where is your problem.
I used the NS_IMPLEMENT_REFLECTION in cpp, still got an error.
may be there some difference between NoesisGUI and WPF.
now I solved my project problem, Register InlineList as Ptr<BaseComponent>, then converter to (ObaservableCollection<Inline>*)
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: confused about ObservableCollection
Our ObservableCollection only works with BaseComponent derived classes or boxed objects (also BaseComponent).
We should probably put an static assert to verify that and make it clear.
In your case it should be an ObservableCollection<BaseComponent> and then use it like this:
And to define a DependencyProperty of this type, you have to include the Ptr in the type:
We should probably put an static assert to verify that and make it clear.
In your case it should be an ObservableCollection<BaseComponent> and then use it like this:
Code: Select all
Ptr<ObservableCollection<BaseComponent>> collection = *new ObservableCollection<BaseComponent>();
collection->Add(Boxing::Box("Item 1"));
const NsString& str = Boxing::Unbox<NsString>(collection->Get(0));
Code: Select all
UIData->RegisterProperty<Ptr<ObservableCollection<Inline>>>(InlineListProperty, "Inline",
FrameworkPropertyMetadata::Create(Ptr<ObservableCollection<Inline>>>(),
FrameworkOptions_None, &OnPropertyChanged));
ObservableCollection<Inline>* GameGUI::RichTextBlock::GetInlineList() const
{
return GetValue<Ptr<ObservableCollection<Inline>>>(InlineListProperty).GetPtr();
}
void GameGUI::RichTextBlock::SetInlineList(ObservableCollection<Inline>* InlineList)
{
SetValue<Ptr<ObservableCollection<Inline>>>(InlineListProperty, InlineList);
}
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 61 guests