Есть такой вот FlowDocument:
<?xml version="1.0" encoding="utf-8"?>
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Section Padding="0,0,0,0" Background="Blue">
<Paragraph BorderThickness="1,1,1,1" BorderBrush="Red" Padding="28,0,0,0">
<Paragraph.Background>
<ImageBrush ImageSource="Arrow.jpg" ViewportUnits="Absolute" Stretch="None"
Viewport="0,0,24,24" TileMode="None">
</ImageBrush>
</Paragraph.Background>Hello brothers</Paragraph>
</Section>
</FlowDocument>
Размер Arrow.jpg 24 на 24 пикселя(скачать можно
здесь)
ViewPort для фоновой картинки установлен в 0,0,24,24 так что я ожидаю что картинка будет рисоваться начиная с верхнего левого угла параграфа.
Тем не менее, картинка начинает рисоваться за пределами параграфа, и в результате видна только маленькая ее часть.
Если установить ViewPort в 15,15,24,24 то все рисуется нормально(примерно)
В чем может быть проблема?
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Section Padding="0,0,0,0" >
<Paragraph BorderThickness="1,1,1,1" BorderBrush="Red" Padding="28,0,0,0">
<Paragraph.Background>
<ImageBrush AlignmentX="Left" ImageSource="Arrow.jpg" Stretch="None"
TileMode="None">
</ImageBrush>
</Paragraph.Background>Hello brothers</Paragraph>
</Section>
</FlowDocument>
Вот так работает
Разобрался:
If you want to fix the number of horizontal and vertical tiles, but you also want to preserve the aspect ratio of the original image, you can set Stretch to Uniform (in which case there will be some blank space on the sides) or UniformToFill (which will truncate part of the image). But don't set Stretch to None, because that causes the image to be displayed in its metrical size. It's likely that the tile will be smaller than the unstretched image and thus will contain only a little part of that image.
Устанавливаем Stretch в Uniform, чтобы сохранить пропорции, устанавливаем ViewPort и ViewPortUnits и работает как режим повторения фоновой картинки так и еденичная фоновая картинка.