在WPF TextBlock中插入嵌入式图像

时间:2018-12-18 16:10:44

标签: c# wpf xaml .net-3.5 textblock

我在边框内的WPF TextBlock下面:

<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>

现在,我想在TextBlock文本的左侧(左侧)和同一行的Textblock文本前面插入一个内嵌图像。我该怎么办?

1 个答案:

答案 0 :(得分:0)

Stackpanel Horizontal添加Orientation

我已删除了绑定,因为它与添加图像无关。

 <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