How to make rounded corner triangle in XAML - xaml

How can I make a rounded corner triangle in XAML-Silverlight?

I think the below Path will solve your problem, Only you need to change the points of your triangle according to your requirement. For more idea about Path
<Path Data="M 300 100 L 500 400 100 400 Z"
StrokeThickness="48"
StrokeLineJoin="Round"
Stroke="Blue"
Fill="Blue" />

Related

SVG Bézier's curve always closes path in browser and PDF

I am drawing music slurs with Bézier's curves in SVG, in order to visualize them in the browser and allow a pdf export.
It works fine. But if you zoom in you can see that there is a line connecting the two vertices: I need to get rid of that line.
In Inkscape, the line is not there, but it does appear in all browsers (especially Chrome), even if it's practically invisible. My problem is that when you print it as a PFD (I just click ctrl+P and save the file) that line becomes much thicker, and the music sheet cannot be published like that!
Here is my path:
<svg height="150px" width="100%"><path d="M 28 39 q 15 29 40 -13 M 28 39 q 15 25 40 -13" stroke="black" stroke-width="0.5" fill="black" fill-rule="evenodd"></path></svg>
Could you please suggest any way to fix this?
curve in Chrome
curve in pdf export
The problem is with the way you have created your shape.
It consists of two individual shapes that you merged together into one path. See the example below where I have given the two subpaths different colours.
<svg width="400px" viewBox="0 0 70 60">
<path d="M 28 39 q 15 29 40 -13" fill="red" opacity="0.5"/>
<path d="M 28 39 q 15 25 40 -13" fill="green" opacity="0.5"/>
</svg>
Notice the top of the shape where the two sub-paths (red and green) share an edge? There is effectively an incredibly thin rectangle along that edge, formed by the edges of the two sub-paths. When the path is rendered to the screen, slight differences in the way the two shapes are drawn, can sometimes cause some pixels to be visible along that edge. That can give the appearence of a light grey line there.
This is also why you needed to add fill-rule="evenodd"to your path. It is so that one sub-path makes a hole in the other. Otherwise they would both be drawn solid.
<svg width="400px" viewBox="0 0 70 60">
<path d="M 28 39 q 15 29 40 -13 M 28 39 q 15 25 40 -13" fill="black"/>
</svg>
The fix is to make sure your shape is one path only. Not two sub-paths. The path should go around the boundary of your shape. From one side to the other and then back along the other side.
<svg width="400px" viewBox="0 0 70 60">
<path d="M 28 39 q 15 29 40 -13 q -25 38 -40 13 Z" fill="black"/>
</svg>
So the fixed version of your original SVG would be as follows:
<svg height="150px" width="100%"><path d="M 28 39 q 15 29 40 -13 q -25 38 -40 13 Z" stroke="black" stroke-width="0.5" fill="black" fill-rule="evenodd"></path></svg>

How to centre Image in Xamarin.Forms without stretching it

I've got this ContentPage:
<ContentPage.Content>
<Grid>
<Image
Source="background.png"
Aspect="AspectFill"
/>
<Image
Source="logo.png"
VerticalOptions="Center"
HorizontalOptions="Center"
/>
</Grid>
</ContentPage.Content>
But logo.png (while vertically and horizontally entered), stretches to take up the entire width of the screen.
How do I stop it from stretching and just maintaining its original size?
And yes, XAML solution definitely preferred.
Edit 1 (based on Paul Kertscher's answer):
If I set the Image source to a URL (e.g. https://via.placeholder.com/450x300.png?text=Computer+Says+No), I get the expected result, i.e the image does not stretch. However, if I save this same image to the specific platform directory (say Resources/ComputerSaysNo.png for iOS), it stretches to take up the entire screen width.
Tested on iPhone 7 simulator.
Edit 2
If I make #2x and #3x copies of my logo.png in the iOS Resources directory, and have all three images the same size, it works differently; the logo does not stretch to take up the entire width of the page.
From the documentation about AspectFill
Scale the image to fill the view. Some parts may be clipped in order to fill the view.
You should use AspectFit instead, it does not stretch the image to fill the control, but to fit the whole image in the control:
Scale the image to fit the view. Some parts may be left empty (letter boxing).
EDIT
I've tried the following
<Grid>
<Image HorizontalOptions="Center"
VerticalOptions="Center"
Source="http://lorempixel.com/output/abstract-q-c-200-200-6.jpg" />
</Grid>
and it yielded the following layout:
Hence it looks like what I've proposed is right - at least principally. I'd guess your image is simply too large.
Anyway, if you want to keep that image or would like to have more control over how the image is displayed, you could opt to either one of the following options.
Use the grid system to determine the size of the image
Within the Grid you can define columns and rows. Columns (and rows respectively) defined with the width (height) of * will take all the available space. If there are multiple columns or rows with * size, they will devide the remaining space equally. Furthermore you can give the * columns and rows weights. Ar column with the width 2* will have twice the width of one with the width *. Hence you could define columns with width 3*, *, and 3* and place your image in the second column (column index 1) for the image to take 1/7th of the screen width.
Use an AbsoluteLayout
Within an AbsoluteLayout you can define positions and sizes of child elements. Instead of positioning the images in a Grid, you could do the following
<AbsoluteLayout>
<Image AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" /> <!-- Background -->
<Image AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds=".5,.5,.2,.2" /> <!-- Logo with 20% width/height -->
</AbsoluteLayout>
If you preferred setting the size of the image absolutely, you can do the following
<Image AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds=".5,.5,150,150" />
Another option which I use quite often is AbsoluteLayout. Combining PositionProportional (LayoutFlags) with LayoutBounds="0.5,0.5,-1,-1 (X, Y, Width, Height) will put image in the center of the screen. The LayoutBounds "0.5" means it will be in the center of X and Y, and "-1" will help to ignore the width and height.
Make sure to set VerticalOptions to in your AbsoluteLayout.
Here is the code:
<AbsoluteLayout VerticalOptions="FillAndExpand">
<StackLayout AbsoluteLayout.LayoutBounds="0.5,0.5,-1,-1" AbsoluteLayout.LayoutFlags="PositionProportional">
<Image Source="http://lorempixel.com/output/abstract-q-c-200-200-6.jpg" />
</StackLayout>
</AbsoluteLayout>
I hope it helps.

How is the margin of a UIElement calculated

For the xml below
<Image Width="30px" Height="30px" Margin="1 1 1 1" />
The margin is 1 1 1 1 but the image is at the centre of the screen (668 369 668 369). Why is this happening? Isn't the margin above invalid? Also, for the position of anything, you just need margin left and margin top. That's how winforms works, right? I don't understand why the Thickness constructer requires 4 values.
A Thickness for a Margin is how many pixels from each edge of the element. These are Left, Top, Right, and Bottom.
Here's an example:
Margin="10,15,5,0"
The code above defines a margin of:
10 Pixels from the Left.
15 Pixels from the Top.
5 Pixels from the Right.
0 Pixels from the Bottom.
The margin is always defined as Left, Top, Right, Bottom. However there are some shortcuts.
For example:
Margin="10,15"
The margin here will be defines as:
10 Pixels on the Left and Right.
15 Pixels on the Top and Bottom.
And also:
Margin="15"
This margin will be 15 pixels on all sides.
To answer your question more directly, you are simply missing the commas.

How can we create a Windows 8 Application which supports in all resolutions?

Which is the best approach to create a windows 8 application which supports all resolutions including Snapped & Filled States .
[1366 X 768
1024 X 768
1920 X 1080
2560 X 1440
1280 X 800
1920 X 1080
2560 X 1440]
I tried with 1366 x 768 as base resolution.
<Grid Background="{StaticResource SEBgColorBrush}">
<Viewbox>
<Grid x:Name="ContentGrid" Height="768" Width="1366" >
//content
</Grid>
</Viewbox>
</Grid>
But it is not supported by 2 resolutions [1024 X 768 & 1280 X 800].
Can anyone have any idea to do this ?
the built in sample apps do a pretty good job of using visualstate, LayoutAwarePage to support the various resolutions and layouts.
Ideally you wouldn't be doing anything to hardcode height or width, you'd be using the various layout systems to place things in relative positions and resize gracefully, instead of explicitly setting sizes and locations.

How can I reduce the field-of-view on a ProjectPlane animation?

In XAML, the ProjectionPlane is used pivot an element on a three-dimensional axis. For example if I wanted to tilt the right edge of a rectangle toward me, I do this:
<!-- zero rotation -->
<Rectangle Fill="White" Height="200" Width="200">
<Rectangle.Projection>
<PlaneProjection RotationY="0" />
</Rectangle.Projection>
</Rectangle>
<!-- 45 deg rotation -->
<Rectangle Fill="White" Height="200" Width="200">
<Rectangle.Projection>
<PlaneProjection RotationY="45" />
</Rectangle.Projection>
</Rectangle>
<!-- 85 deg rotation -->
<Rectangle Fill="White" Height="200" Width="200">
<Rectangle.Projection>
<PlaneProjection RotationY="85" />
</Rectangle.Projection>
</Rectangle>
The resulting rectangle(s) would look like this:
So far so good. Here's my problem. As the angle increases closer to 90 degrees, the rectangle is skewed more and more. Is there a property or technique that could allow the ProjectionPlane to rotate along the Y axis all the way to 90 degrees but reduce the scewing (or change the field of view)?
In other words, the angle from the back corners to the from corners would be decreased and as a result if the rectangle had content in it, it would be more discernible.
Here's a before and after to make the question as clear as possible. On the left is what I get. On the right is what I want. It is slightly exaggerated to make the point. I hope this makes sense.
Unfortunately PlaneProjection doesn't allow you change projection matrix. To get control over projection you would have to go with Matrix3DProjection. You can use sample code provided in the documentation or you could look into porting Matrix3DEx library to WinRT.
One more thing you can try is to push your object back along Z axis and scale it up so it keeps it size. Since object would be further away from the camera it would show less distortion on flip.
BTW Accordingly to Jaime Rodriguez fov for PlaneProjection is set to 57 degrees, a bit wide for most displays.