Reputation: 57
I'm presently learning WPF and C# programing with Visual Studio 2015.
I actually get an error using TextBlock in XAML which I don't understand.
Using this code:
<TextBlock>
Text example
</TextBlock>
VS shows me the following error:
A value of type 'String' cannot be added to a collection or dictionary of type 'InlineCollection'.
This error doesn't prevent compilation and the application still work but it makes programming harder as my error list box is full of messages as for every inline text there is an error message.
The only way I found to prevent the situation is to put texts with the Text="" property but this method makes formatting text way much harder.
Anybody have a solution for this issue?
Thanks.
Edit:
I should have wrote a real example of code from the book I'm reading to clarify the question:
<TextBlock FontSize="14"
TextWrapping="Wrap">
<Bold><Italic>Instructions:</Italic></Bold>
<LineBreak />
Select a <Underline>font</Underline> to view from the list <Italic>below</Italic>.
<Span FontSize="10">
You can change the text by typing in the region at the bottom.
</Span>
</TextBlock>
That represent the kind of formatting I want to do.
Upvotes: 1
Views: 1183
Reputation: 57
The solution is the selection of .Net version as seen in the last comment to the question.
Upvotes: 0
Reputation: 57
We can use Run for inline style like
<TextBlock>
<Run Text="Hello World"></Run>
<Underline>
<Run Text="Hello World"></Run>
</Underline>
<Bold>
<Run Text="Hello World"></Run>
</Bold>
</TextBlock>
Upvotes: 2
Reputation: 6375
What you should do is this:
<TextBlock Text="Text example">
What kind of formatting are you trying to do? You can do things like:
<TextBlock Text="Text example" FontSize="45" FontWeight="Bold">
There are many more options. VS2015's Intellisense can help you discover what attributes are available.
Upvotes: 0