Search code examples
c#wpfxaml.net-3.5textblock

Insert an inline image within a WPF TextBlock


I have below WPF TextBlock within a border:

<Border Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}" BorderThickness="1" BorderBrush="Red" CornerRadius="5" Margin="5">                    
    <TextBlock x:Name="lblStoryboard"
               TextAlignment="Center"
               Padding="5"                                                         
               Width="Auto"    
               Background="Red"
               Foreground="Black"
               FontSize="12.5"
               FontWeight="Bold"
               Style="{StaticResource BlinkingTextBlock}"
               Text="Hi there!" 
               TextWrapping="WrapWithOverflow"
               Visibility="{Binding Path=BlinkOn, Converter={StaticResource BoolToVis}}">
    </TextBlock>
</Border>

Now I am trying to insert an inline image in front of the Textblock text, I mean, to the left (left side) of the TextBlock text and in the same line. How can I do this?


Solution

  • Add Stackpanel with Horizontal Orientation.

    I have removed the binding since it as nothing to do with Adding image.

     <Border   BorderThickness="1" BorderBrush="Red" CornerRadius="5" Margin="5">
            <StackPanel Orientation="Horizontal" Margin="0,0,0,-1">
                <Image Source="C:\Users\Administrator\source\repos\WpfApp4\WpfApp4\Koala.jpg" Margin="0,459,0,0"  />
                <TextBlock x:Name="lblStoryboard"
                  HorizontalAlignment="Center"
               TextAlignment="Center"
               Padding="5"                                                         
               Width="Auto"    
               Background="Red"
               Foreground="Black"
               FontSize="12.5"
               FontWeight="Bold"
    
               Text="Hi there!" 
               TextWrapping="WrapWithOverflow" Margin="0,459,0,0"
            />
            </StackPanel>
        </Border>
    

    enter image description here