Windows Phone cut part of element (rectangle) - windows

I don't know how to cut center of element (do center of element clear [sorry for my english]). I think to use opacity mask but i can't create this. I need create like this

<Rectangle Fill="#FFFF0000" Height="100" Width="100" />
<Rectangle Fill="#FF00FF00" Height="100" Width="100">
<Rectangle.OpacityMask>
<ImageBrush Stretch="Fill" ImageSource="mask.png"/>
</Rectangle.OpacityMask>
</Rectangle>

Related

How to Customize Button's Size?

I have problem to customize the buttons' size in my stack panel. I made one experiment with Rectangle, it looks perfect, here is the code in the XAML:
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Rectangle Width="170" Height="170" Fill="Bisque" Margin="10,0,0,0" />
<StackPanel Orientation="Vertical" Margin="10,0,0,0">
<StackPanel Orientation="Horizontal">
<Rectangle Width="80" Height="80" Fill="Azure" />
<Rectangle Width="80" Height="80" Fill="Azure" Margin="10,0,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Rectangle Width="80" Height="80" Fill="Tomato" />
<Rectangle Width="80" Height="80" Fill="Azure" Margin="10,0,0,0" />
</StackPanel>
</StackPanel>
</StackPanel>
Here is the screen shot:
But, when I remove those Rectangles to Buttons,
like these in the XAML:
<Button x:Name="Btn2" >
</Button>
<Button x:Name="Btn3" Width="40" Height="40" Margin="11,0,0,0" >
</Button>
it looks not what i want:
I can't resize those 2 buttons. How to get a quick solution for this?
Buttons in WP8.1 have deafault minimum width - MinWidth property - try changing it and it should help.
A side note - consider using Grid panel instead of StackPanel for positioning elements. If you define some Rows and Columns, your app should scale correctly when used on different devices.

How to make Ellipse animation (Windows Phone 8 - c#)

I have an ellipse, and I want to make an animation to show this ellipse.
The animation should do something like this gif:
http://media.giphy.com/media/qiutE2wCo1YXe/giphy.gif
But instead of the ellipse disappear, it starts from zero and ends full.
Does anybody can help me with this?
You can make it by splitting the ellipse in half and animate two pieces of it separately. Here's my solution that implements the idea.
First of all, you have to define shapes to animate. I use Canvas as a container.
<Canvas Width="100"
Height="100">
<Canvas.Clip>
<EllipseGeometry RadiusX="50"
RadiusY="50"
Center="50, 50" />
</Canvas.Clip>
<Canvas>
<Canvas.Clip>
<RectangleGeometry Rect="0, 0, 50, 100" />
</Canvas.Clip>
<Rectangle x:Name="HalfLeft"
Width="50"
Height="100"
Fill="Red"
Canvas.Left="0"
Canvas.Top="0">
<Rectangle.RenderTransform>
<RotateTransform Angle="-180"
CenterX="50"
CenterY="50"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
<Canvas>
<Canvas.Clip>
<RectangleGeometry Rect="50, 0, 50, 100" />
</Canvas.Clip>
<Rectangle x:Name="HalfRight"
Width="50"
Height="100"
Fill="Red"
Canvas.Left="50"
Canvas.Top="0">
<Rectangle.RenderTransform>
<RotateTransform Angle="-180"
CenterX="0"
CenterY="50"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Canvas>
You can modify Angle value to see how it works. I set -180 degrees, so they are invisible, but the angle will be animated to 0.
Then you need two animations in one storyboard. I have added it to main page resources.
<phone:PhoneApplicationPage.Resources>
<Storyboard x:Name="FillAnimation">
<DoubleAnimation Storyboard.TargetName="HalfLeft"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
From="-180"
To="0"
BeginTime="00:00:01"
Duration="00:00:01"/>
<DoubleAnimation Storyboard.TargetName="HalfRight"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
From="-180"
To="0"
Duration="00:00:01"/>
</Storyboard>
</phone:PhoneApplicationPage.Resources>
And that's it. The last thing you have to do is to run the animation from code.
FillAnimation.Begin();
Screenshot:

Disable interpolation of child elements in Windows RT

Right now I have a ScrollViewer control in a Windows Store Application which surrounds an Image element. I am trying to make a pixel art editor but when the ScrollViewer is zoomed in the Image's contents are interpolated. Is there currently any way to force the image to be scaled in nearest neighbor mode?
EDIT: I decided I should put some code to clarify what I'm trying to do, so here it is:
<ScrollViewer
x:Name="Container"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ZoomMode="Enabled"
MinZoomFactor="0.1"
MaxZoomFactor="100"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Enabled"
VerticalScrollBarVisibility="Auto"
ViewChanged="OnContainerViewChanged">
<Border
x:Name="ImageBorder"
Width="32"
Height="32"
BorderBrush="White"
BorderThickness="4">
<Grid>
<Image
x:Name="RenderedImage"/>
<Image
x:Name="EditPreview"/>
<Canvas
x:Name="GridContainer"
Visibility="Collapsed"/>
<Rectangle
x:Name="InputCapturer"
Fill="Transparent"
PointerPressed="OnPointerPressed"
PointerMoved="OnPointerMoved"
PointerReleased="OnPointerReleased"
PointerExited="OnPointerLeave"/>
</Grid>
</Border>
</ScrollViewer>

How to add Text To Shapes in Blend Expressions 4?

I am looking at the shapes available in Blend Expression 4 for my WP7 app I am making. I am a bit confused though how to add text to a shape.
How do I add text to a shape?
Shapes in Blend for WP7 are simply ... Shapes.
All Expression Shapes inherits from Path, that inherit from System.Windows.Shapes.Shape. Shape is a base class for creating graphics. It supports only very basics properties such as fill, stroke, transform, ... you can not add text inside a shape because it's a pure-graphical object.
Hopefully for you, because they derive from UIElement, shape objects can be used inside panels and most WP controls. The Canvas panel is a particularly good choice for creating complex drawings because it supports absolute positioning of its child objects.
So, two examples can be
<Grid>
<es:RegularPolygon Fill="#FFF4F4F5" Height="100" InnerRadius="1" PointCount="6" Stretch="Fill" Stroke="Black" Width="100" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="Hello" Foreground="black"/>
</Grid>
or
<Canvas Height="200" Width="200">
<es:RegularPolygon Canvas.Left="50" Canvas.Top="50" Fill="#FFF4F4F5" Height="100" InnerRadius="1" PointCount="6" Stretch="Fill" Stroke="Black" Width="100" />
<TextBlock Canvas.Left="75" Canvas.Top="85" VerticalAlignment="Center" HorizontalAlignment="Center" Text="Hello" Foreground="black"/>
</Canvas>

Is there any way to get XAML element by Tag property?

Is there any way to get the XAML element by its tag value??
My code is like this :
<Grid Tap="StackPanel_Tap" Tag="{Binding Type}" >
<Border BorderThickness="0" CornerRadius="0" BorderBrush="White" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="1" >
<Image Tag="{Binding Type}" Source="{Binding Location}" Opacity="1" Width="100" Height="100" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" UseLayoutRounding="True" >
</Image>
</Border>
</Grid>
I am binding Tag Property for Grid , is there any way to get an object of Grid by using Tag Propertty??
Sorry for less information the thing is grid is in ListBox ..
How can i Access The Grid Object??
Thanks and Reagrds
Yashavantha
Create a recursive method which uses System.Windows.Media.VisualTreeHelper to get all children of the page. For each child test if it's of type Grid and if it has a Tag equal to whatever you're looking for.

Resources