ImageBrush In WPF

Here we take an example to paint an Image on a TextBlock with the help of ImageBrush Property.

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <StackPanel>
            <!--Code For TextBlock without an ImageBrush -->
            <TextBlock
FontSize="32"
FontFamily="Arial"
FontWeight="Bold">
Mahak Gupta
</TextBlock>
            <!--Code For TextBlock with an ImageBrush -->
            <TextBlock
FontSize="32"
FontFamily="Arial"

FontWeight="Bold">
Mahak Gupta
<!-- Add an Image as the foreground -->
<TextBlock.Foreground>
<ImageBrush ImageSource="Images/28092011950.jpg"
Stretch="Fill"/>
</TextBlock.Foreground>
</TextBlock>
</StackPanel>

    </Grid>
</Window>

1.png
Ebook Download
View all
Learn
View all