Background with several paths - wpf

Is there a way I can put a background like this in a border:
The problem in there is that both the circle and the square must be a path (in my real problem I actually have 3 paths and they're gradients), and this makes it extremely problematic to resize, align, etc. I saw this solution but I had already tried using a viewbox and it didn't solve my problem.
Is there a way I can combine both the square and the circle into a path and keep the colors, and then set it as a background?
I don't have the real button around here, so I'll post it tomorrow, but it has several gradients to make some glossy effect and some Bezier curves to make the effect more "realistic". In the mean time the effect looks something like this:
Thanks for any help.

Don't quite understand why the ViewBox would not work but alternatively you can use a DrawingBrush, e.g.:
<Border Width="300" Height="300">
<Border.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Blue">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="Red">
<GeometryDrawing.Geometry>
<EllipseGeometry Center="50,50" RadiusX="35" RadiusY="35" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
</Border>

Related

Wpf canvas grid with coordinates

I have following canvas Code:
<Canvas>
<Canvas.Background>
<DrawingBrush TileMode="Tile" Viewport="0,0,40,40"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,400,400"/>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="1"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
</Canvas>
This canvas generates a grid like you can find it on excel.Now I want to know if ist possible to generate the coordinates too. With cooridnates I mean that the first top row in the first fiels has a tiny text in it that says "A0" and the next one has "B0" and so every cell has coordinates like Excel.Would this be possible?

Draw special background

Is it possible in WPF to draw the background of a window the following way:
the background of the window is for instance white
vertical colored lines of 20 pixels width with a same-size gap in between, so that you get a red-striped pattern
horizontal colored lines of 20 pixels height in the same color, also with a same-size gap in between
the areas where the horizontal and vertical red lines overlap each other should be shown in white again, so that you get kind of a checkered pattern
I know how to draw lines in WPF and I know how to repeat a drawing to fill the whole background, but I don't know how the manage the part with the overlapping colors vanishing.
Not sure how large the gap is supposed to be. You may however adjust a DrawingBrush like this:
<Window.Background>
<DrawingBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,100,100">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing
Geometry="M50,0 L50,40 M50,60 L50,100 M0,50 L40,50 M60,50 L100,50">
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="20"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Background>
Or with another TileMode:
<Window.Background>
<DrawingBrush TileMode="FlipXY" ViewportUnits="Absolute" Viewport="0,0,50,50">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="White">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,50,50"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Geometry="M0,45 L40,45 M45,0 L45,40">
<GeometryDrawing.Pen>
<Pen Brush="Red" Thickness="10"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Background>

DrawingBrush to WPF DataGrid cells as Background

I'd like to set a DrawingBrush to DataGridCelland I use
<DrawingBrush TileMode="Tile" ViewportUnits="RelativeToBoundingBox" Viewport="0,0,0.05,1">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Gray" Thickness="0.05"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,1" EndPoint="1,0" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
I have undesired result when DataGridCells have unequal widths like below.
How should I change the Brush so that regardles of the widht of the individual cells the result would look like this.
Change ViewportUnits from RelativeToBoundingBox to Absolute and adjust Viewport.
The coordinate system is not relative to a bounding box. Values are interpreted directly in local space.
Something like this:
<DrawingBrush
x:Key="DrawingBrush"
TileMode="Tile"
ViewportUnits="Absolute"
Viewport="0,0,5,15">
which looks like this

How to create a shape with a gradient fill, and add it to a border background in WPF

I am trying to create the following shape as a background to a border. You will notice that the bottom section on the shape has a linear gradient to it.
I have played around with lines and shapes and gradients, but i have not been able to apply the below to a border. nor can i get a shape that looks like that.
Is this even possible? if so, can anyone help
The below XAML produces a brush that looks similar to your picture. You should play around the colors, offsets, and the rest for the best appearance.
<DrawingBrush x:Key="br1" Viewbox="0,0,100,100" ViewboxUnits="Absolute" >
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Lavender">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing>
<GeometryDrawing.Brush>
<RadialGradientBrush GradientOrigin="0.5,0.01" Center="0.5,-0.2" RadiusX="100">
<GradientStop Color="MidnightBlue" Offset="1.0" />
<GradientStop Color="LightSteelBlue" Offset="0.0" />
</RadialGradientBrush>
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<EllipseGeometry Center="60,310" RadiusX="160" RadiusY="300" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
Have fun!

Repeat a background brush in WPF

and thank you.
This question is very similar to this old, unanswered question here:
How to paint notebook-like lines as TextBox background? However, it is not the same - not exactly.
I would like to create a notepad, lined paper-like background but I am not not familiar with how to repeat a brush in XAML. How do you?
EDIT
Here's the solution as part of a TextBox:
<TextBox TextBlock.LineHeight="20"
TextBlock.LineStackingStrategy="BlockLineHeight"
Padding="20,10,20,20" TextWrapping="Wrap">
<TextBox.Background>
<DrawingBrush TileMode="Tile" Stretch="None" Viewport="0,0,20,20"
ViewportUnits="Absolute" Opacity=".07">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="RoyalBlue" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,0" EndPoint="20,0"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</TextBox.Background>
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
</TextBox>
<DrawingBrush TileMode="Tile" Stretch="None"
Viewport="0,0,20,20" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Gray"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,0"
EndPoint="20,0"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
Funny, was just doing the same thing. Here ya go. You will probably have to play with the TileMode to set the direction of the tiling, and the ViewPort, the last two numbers should be the width/height of your image (I had to do this because my image was being stretched or just not coming out right).
<ImageBrush x:Key="WindowBackground" ImageSource="/Images/Background.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,4,4" />
Use an ImageBrush
<ImageBrush ImageSource="image.png" TileMode="Tile"/>

Resources