I'm try convert my app framework to MVVM
and currently, I'm stuck at try to bind the TextBlock
This TextBlock
on old project is update with code behind by adding new Run
to the TextBlock
somewhat like this
On MainPage.xaml
<Page>
<!--other items on page-->
<TextBlock x:Name="textUI"/>
</Page>
On MainPage.xaml.cs
public sealed partial class MainPage : Page
{
void AddText(string text, bool mark)
{
if (mark)
{
textUI.Inlines.Add(new Run()
{
Text = text,
Foreground = new SolidColorBrush((Color)Resources["SystemAccentColor"]) });
}
else
{
textUI.Inlines.Add(new Run() { Text = text });
}
}
}
Here's the question
Instead, I try thinking other idea. And that idea was making List
of class like this
public class Blocks
{
public string text;
public bool mark;
}
And put that on the list and bind it like on ListView
but on the TextBlock
instead
Like this
<TextBlock ItemSource={x:Bind ListOfBlocks}>
<Run Text={x:Bind text,Mode=OneWay} Foreground={x:Bind mark, Converter={StaticResource SomeConverter}, Mode=OneWay }
</TextBlock>
Is it possible?