I make my Textblocks in C# code and i want to bind JSON data to it. At this moment i want to do it like this:
if (actualStock == true)
{
TextBlock TBActualStock = new TextBlock();
TBActualStock.Text = "Actuele voorraad: ";
TBActualStock.FontSize = 18;
STACKActualStockDeliverTime.Children.Insert(1, TBActualStock);
TextBlock TBBindActualStock = new TextBlock();
TBBindActualStock.Text = "{Binding ActualStock}"; //this is where it should bind
TBBindActualStock.FontSize = 18;
STACKActualStockDeliverTime2.Children.Insert(1, TBBindActualStock);
}
This is my XAML code:
DataContext="{Binding Item}"
d:DataContext="{Binding Groups[0].Items[0]}">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="/Assets/BackGroundGAC.jpg" Stretch="UniformToFill"/>
</Grid.Background>
<Grid Grid.Row="1" x:Name="contentRegion">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<StackPanel x:Name="STACKActualStockDeliverTime">
<TextBlock x:Name="HEADERActualStockDeliverTime" FontSize="24" Text="Voorraad en levertijd"></TextBlock>
</StackPanel>
<StackPanel x:Name="STACKActualStockDeliverTime2">
<TextBlock x:Name="Headert" FontSize="24" Text=""></TextBlock>
</StackPanel>
</StackPanel>
Now I want add the Json data to the textblock i make in the C# code. i know in XAML i should use {Binding description} //description is a part of my json object so that works
But if i do this in C# code it will just set the text to {Binding Description}
Any idea how i can solve this problem?
ps: I need to do it in C# code and not in XAML.