Dôn Kayt
Dôn Kayt

Reputation: 103

How can I Binding my Text after the Border?

I use 3 Columns. In the first, I put a simple Border, no problem with it but in my third Column I want to have a Text in the Border and just after (in to the right) begin my Text with Wrap possibility. To insert a Text, it's easy but I want to use a Binding to make it dynamical. See my codes below please.

<Grid Grid.Row="1">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="10"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="0" Background="Red" Height="15" Width="15" BorderBrush="Red" CornerRadius="100" Margin="5" Padding="5" VerticalAlignment="Top"/>
    <DockPanel Grid.Column="2" >
        <TextBlock TextWrapping="WrapWithOverflow"  Height="60" Width="450" LineHeight="20" LineStackingStrategy="BlockLineHeight" MaxWidth="{Binding ElementName=myWindowName, Path=ActualWidth}">
                <Border Background="Red" CornerRadius="10" Padding="10,0,10,0" Margin="0 -16 0 -5" Visibility="Visible" >
                    <TextBlock Text="Color and random text" Foreground="White" FontSize="12" FontWeight="Medium" />
                </Border>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
            incididunt ut labore et dolore magna aliqua. 
        </TextBlock>
    </DockPanel>
</Grid>

Upvotes: 2

Views: 63

Answers (1)

mm8
mm8

Reputation: 169270

Put the dynamic text in a Run element:

<TextBlock TextWrapping="WrapWithOverflow"  Height="60" Width="450" LineHeight="20" LineStackingStrategy="BlockLineHeight" 
        MaxWidth="{Binding ElementName=myWindowName, Path=ActualWidth}">
    <Border Background="Red" CornerRadius="10" Padding="10,0,10,0" Margin="0 -16 0 -5" Visibility="Visible" >
        <TextBlock Text="Color and random text" Foreground="White" FontSize="12" FontWeight="Medium" />
    </Border>
    <Run x:Name="run" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " />
</TextBlock>

If you give the Run element an x:Name, you can set its Text property dynamically from the code-behind. You may also bind its Text property to a source property of a view model:

<Run Text="{Binding DynamicText, Mode=OneWay}" />

Upvotes: 1

Related Questions