-
- realm_mike
- Posts: 5
- Joined:
Binding to Inlines of TextBlock
In the TextBlock documentation I see:
So is it possible to bind an inlines collection to the Inlines property?
I don't see any errors being logged from Noesis, but the inline elements also don't show up in the textblock. Is this sort of thing possible to do?
Code: Select all
A TextBlock can contain a string in its Text property or Inline flow content elements, such as Bold, Hyperlink, and InlineUIContainer, in its Inlines property.
Code: Select all
<TabControl TabStripPlacement="Left" x:Name="TellsTabs">
<TabControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Sender}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBlock Inlines="{Binding Text}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Code: Select all
struct RealmUI_Tell : Noesis::BaseComponent
{
Noesis::String sender;
Noesis::Ptr<Noesis::InlineCollection> text = Noesis::MakePtr<Noesis::InlineCollection>();
const Noesis::String& GetSender() const { return sender; }
Noesis::InlineCollection* GetText() const { return text; }
NS_IMPLEMENT_INLINE_REFLECTION(RealmUI_Tell, Noesis::BaseComponent)
{
NsProp("Sender", &RealmUI_Tell::GetSender);
NsProp("Text", &RealmUI_Tell::GetText);
}
};
-
-
sfernandez
Site Admin
- Posts: 2869
- Joined:
Re: Binding to Inlines of TextBlock
The Inlines property is read-only. When assigning a binding it just tries to add it to the collection, and Noesis outputs an error saying "Cannot add a 'BindingExpression' to a 'InlineCollection'".
Maybe you are trying to achieve something similar to our RichText extension, which automatically generates the inlines from a formatted text. Is that what you are looking for?
Maybe you are trying to achieve something similar to our RichText extension, which automatically generates the inlines from a formatted text. Is that what you are looking for?
-
- realm_mike
- Posts: 5
- Joined:
Re: Binding to Inlines of TextBlock
Similar to RichText, but not quite the same I think. For one, the actual TextBlock is inside a DataTemplate so I was hoping to use bindings to get at the data rather than needing the C++ code to get at the actual UI element.
Secondly, this is a TextBlock that I want to append lines to over time, so I don't really want a single 'text' property that has to re-parse the entire text every time a new line is added. The Inlines collection seemed to handle this pretty well where I could create a Span representing the new line to add, and then just Add it to the inlines collection.
I suppose the other way I could do this would be to do something like what the RichText control does, but in the 'getter' for the text on the view model class, it could be a destructive Get, so that any time the Text property changes, the UI 'gets' the text but treats it as text to append. It's a bit of an awkward design but I suppose it could work.
Is there a reason the inline collection must be read-only and can't support coming from bindings?
Secondly, this is a TextBlock that I want to append lines to over time, so I don't really want a single 'text' property that has to re-parse the entire text every time a new line is added. The Inlines collection seemed to handle this pretty well where I could create a Span representing the new line to add, and then just Add it to the inlines collection.
I suppose the other way I could do this would be to do something like what the RichText control does, but in the 'getter' for the text on the view model class, it could be a destructive Get, so that any time the Text property changes, the UI 'gets' the text but treats it as text to append. It's a bit of an awkward design but I suppose it could work.
Is there a reason the inline collection must be read-only and can't support coming from bindings?
-
-
sfernandez
Site Admin
- Posts: 2869
- Joined:
Re: Binding to Inlines of TextBlock
You can have an attached property that can be bound to an observable collection of lines. And then the attached property will fill the InlineCollection as you said, adding a Span for each line. And even listen to changes in the observable collection to update the inlines without needing to reparse any text.
Code: Select all
<TextBlock local:TextHelper.Lines="{Binding TextLines}" .../>
The Inlines collection is created by the TextBlock itself and interacts with the TextBlock, so it cannot be something external.Is there a reason the inline collection must be read-only and can't support coming from bindings?
Who is online
Users browsing this forum: No registered users and 2 guests