Create semi-circle blur effect on a Grid - silverlight

I want to develop a WindowsPhone 8 app with a home page like the fourth phone on this page. The one with a mountain.
You can see an image with two layers over it. My problem is that I don't know how to call that effect in English, and also, I don't know how to do it.
Maybe I will need to make three copies of my image: one untouched, a second one with, a blur effect? and a third one with a 'bigger' blur effect.
Or maybe, I have to add two Grids with some white background and with an opacity less than 100%.
How would you do it?

Your solution is just a good one, I would the samething, and I don't expect that application to be implementing something different, in détails I would do :
One Grid with High Blur on the background.
Another Grid with middle Blur on the front. I'll use an OpacityMask set to a RadialGradientBrush to create that ring effect just like in here : http://msdn.microsoft.com/en-us/library/bb979637(v=vs.95).aspx
And one lase Grid with no Blur in the Front of The previous Grid again with a OpacityMask also set to a RadialGradientBrush.
The three Grids will all have the same Background TileBrush, example :
The Result I've made :
Code :
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="The effect you asked, with :" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="That's Clapton" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel1" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<ImageBrush ImageSource="Eric_Clapton_Blur3.jpg" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
<Grid x:Name="ContentPanel2" Grid.Row="1" Margin="12,0,12,0">
<Grid.OpacityMask>
<RadialGradientBrush Center="0.5,0.5">
<RadialGradientBrush.RelativeTransform>
<CompositeTransform CenterY="0.5" CenterX="0.5" TranslateX="0.4" ScaleX="1.4"/>
</RadialGradientBrush.RelativeTransform>
<!-- This gradient stop is partially transparent. -->
<GradientStop Color="#00000000" Offset="1" />
<!-- This gradient stop is partially transparent. -->
<GradientStop Color="#20000000" Offset="0.741" />
<!-- This gradient stop is fully opaque. -->
<GradientStop Color="#FF000000" Offset="0.728" />
</RadialGradientBrush>
</Grid.OpacityMask>
<Grid.Background>
<ImageBrush ImageSource="Eric_Clapton_Blur2.jpg" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
<Grid x:Name="ContentPanel3" Grid.Row="1" Margin="12,0,12,0">
<Grid.OpacityMask>
<RadialGradientBrush Center="0.5,0.5">
<RadialGradientBrush.RelativeTransform>
<CompositeTransform CenterY="0.5" CenterX="0.5" TranslateX="0.4" ScaleY="0.6"/>
</RadialGradientBrush.RelativeTransform>
<!-- This gradient stop is partially transparent. -->
<GradientStop Color="#00000000" Offset="1" />
<!-- This gradient stop is partially transparent. -->
<GradientStop Color="#20000000" Offset="0.741" />
<!-- This gradient stop is fully opaque. -->
<GradientStop Color="#FF000000" Offset="0.728" />
</RadialGradientBrush>
</Grid.OpacityMask>
<Grid.Background>
<ImageBrush ImageSource="Eric_Clapton.jpg" Stretch="UniformToFill"/>
</Grid.Background>
</Grid>
I know I didn't do it with perfection, and I used terrible naming for the Elements, It's just I've just woke up, and didn't even take my breakfast, hope that helps.

Related

How to add drop shadow to just one specific side in WPF?

I am trying to achieve a grid, with a shadow on just one side and no trace of any shadow on any of the other sides. I tried fiddling around with the direction property of the DropShadowEffect.
What I have tried:
<Grid Background="Transparent" Grid.Row="0" Grid.Column="1">
<Grid Background="White"/>
<Border CornerRadius="0,5,0,0" BorderBrush="White" BorderThickness="0" Background="White">
<Border.Effect>
<DropShadowEffect BlurRadius="5" Direction="355" RenderingBias="Quality" ShadowDepth="2"/>
</Border.Effect>
</Border>
</Grid>
</Grid>
This is what happens with my code:
I want to achieve a drop shadow only visible on the bottom side of the grid, and no trace of the shadow on any of the other sides. The above code leaves a thin gray trail on the left side, which wouldn't work for me.
Sorry if this is a silly question, I am kinda new to WPF.
I don't think the DropShadowEffect has any functionality built-in for this sort of application, however, I managed to achieve the required result using a rectangle and filling it with a linear gradient.
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.3">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#00131313" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
To maintain the same width as the parent of the shadow, add them to the same grid and the same column, set the horizontal and vertical alignment to stretch and the shadow will look consistent.
Then I positioned the rectangle in place of the shadow. Seems a little wanky, but works nonetheless.
Edit:
I found another solution which seems way more better, using the ClipToBounds property and the BorderThickness property.
<Border ClipToBounds="True" BorderBrush="White" BorderThickness="0,2,0,0">
<Border.Effect>
<DropShadowEffect ShadowDepth="2" BlurRadius="10"/>
</Border.Effect>
</Border>
Using a border and a drop shadow is easier than using a rectangle and tweaking it till it looks natural.
Usage of grids is advised to position the border perfectly.

Resizing window sizes in WPF after orientation and sizeToContent changes

I am having a problem when it comes to going from Horizontal orientation to Vertical orientation and back to Horizontal on a stackpanel with the window SizeToContent property being changed as well. Here's my problem: whenever I go back and forth from vertical to horizontal or vice versa, I change the sizetocontent given the way the menu i am creating as to be done. However, i can't get the window to resize back to an appropriate size as before. For example:
State A:
this.SizeToContent = Manual
this.topLevelStackPanel.Orientation = Horizontal
State B
this.SizeToContent = WidthAndHeight
this.topLevelStackPanel.Orientation = Vertical
When state A is valid, the restore bounds for the window has this value: 22,29,960,22
When i go from A to B, the restore bounds changes to -1932, -532, 3212, 1092
Now i attempt to go back fro B to A, and the restore bounds don't get changed back to 22,29,960,22
Rather what I get is a huge window that covers up my screen. How do I reset the sizes and go back to the prior state. I have been stuck on this for a while now.
Here's my XAML
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF528ab5" Offset="0"/>
<GradientStop Color="#FF002d62" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Window.ContextMenu>
<ContextMenu>
<MenuItem Header="Exit" Click="ExitContextMenuItem_Click" />
</ContextMenu>
</Window.ContextMenu>
<Window.BorderBrush>
<SolidColorBrush />
</Window.BorderBrush>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Name="settingsExitStackPanel">
<Image x:Name="SettingsButton" HorizontalAlignment="Left" Source="Images/gear_icon.png" MouseDown="SettingsButton_MouseDown"/>
<TextBlock x:Name="pholder" Text=" " />
<Button x:Name="ExitButton" Content="X" Width="30" FontWeight="Bold" Click="ExitContextMenuItem_Click"/>
<TextBlock x:Name="pholder2" Text=" " />
</StackPanel>
</Grid>

How to set the back ground color of grid-column in wpf?

I have a wpf mvvm application.
And have a GRID with multiple columns
whats best way to set the back ground color of grid-column in wpf?
dabble125's answer was perfect but to give you a sample and to mention a note that it is important where to place your rectangle see the code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- this is not a good place for text block.
the text block is beneath the rectangle
so it would not be seen -->
<!--<TextBlock Grid.Column="1" Text="Some Text"/>-->
<Rectangle Grid.Column="1" Grid.RowSpan="1000">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF83FF97" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Column="1" Text="Some Text"/>
</Grid>
One way:
Create a rectangle and set its fill to the color of your choice.
Then set its Grid.RowSpan value to a large number or the number of rows you have.
Create a rectangle and set its fill to the color of your choice.
Only having :
<Rectangle
Grid.Column="1"
Fill="#e8ebf1" />
works for me.
The Grid.RowSpan of previous answers is actually useless, and the LinearGradientBrush demonstrated is over-complicated for what is asked.

How to apply "Uniform" stretch property to a composite path with gradients in WPF/XAML?

Folks
I am trying to draw my company's logo vectorially with XAML, in order to put it inside UI containers whenever it is convenient.
The only requisite is that the logo won't be clipped or deformed, so the "Uniform" stretch property is what I am looking for.
Sample "semi-working" code is below:
<Grid Width="160" Height="153" >
<Rectangle Clip="M 80,0 c 41.793,0 75.879,34.086 75.879,75.878 0,0.75 -0.015,1.496 -0.036,2.24 l -33.846,-57.969 -42.204,80.387 -39.421,-68.175 -35.758,34.917 c 4.294,-37.769 36.501,-67.278 75.386,-67.278 z" Margin="0">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="44,14" Center="44,44" RadiusX="125" RadiusY="125" MappingMode="Absolute">
<GradientStop Color="#FF1C545C" Offset="0.63"/>
<GradientStop Color="#FF3BB3C3" Offset="0.23"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Clip="M 151,102 c -10.528,29.287 -38.601,50.33 -71.436,50.33 -36.935,0 -67.845,-26.625 -74.533,-61.662 l 32.586,-31.299 42.204,75.131 44.986,-84.096 26.193,51.596 z">
<Rectangle.Fill>
<RadialGradientBrush RadiusY="100" RadiusX="100" GradientOrigin="49,87" Center="49,87" MappingMode="Absolute">
<GradientStop Color="{DynamicResource MarinhoMiotec}" Offset="0.27"/>
<GradientStop Color="#FF003052" Offset="0.63"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
The problem is: when I put this grid inside another icon-sized grid, the drawing does not shrink to uniformly fit inside it.
I guess it is so because the grid where the rectangles are drawn has fixed heigth and width. I already tried to create a single discontinuous path, but then I could not put different colors on each half of the logo.
Should I chose a different container, or should I make the coordinates relative, or use a transform, or create a style, or make a brush... I am confused with so many possible lines of action...
Any help would be appreciated.
Thanks for reading
Try wrapping your logo inside a ViewBox: http://msdn.microsoft.com/en-us/library/system.windows.controls.viewbox.aspx
Here is an example:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<Viewbox>
<Grid Width="160" Height="153" >
<Rectangle Clip="M 80,0 c 41.793,0 75.879,34.086 75.879,75.878 0,0.75 -0.015,1.496 -0.036,2.24 l -33.846,-57.969 -42.204,80.387 -39.421,-68.175 -35.758,34.917 c 4.294,-37.769 36.501,-67.278 75.386,-67.278 z" Margin="0">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="44,14" Center="44,44" RadiusX="125" RadiusY="125" MappingMode="Absolute">
<GradientStop Color="#FF1C545C" Offset="0.63"/>
<GradientStop Color="#FF3BB3C3" Offset="0.23"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle Clip="M 151,102 c -10.528,29.287 -38.601,50.33 -71.436,50.33 -36.935,0 -67.845,-26.625 -74.533,-61.662 l 32.586,-31.299 42.204,75.131 44.986,-84.096 26.193,51.596 z">
<Rectangle.Fill>
<RadialGradientBrush RadiusY="100" RadiusX="100" GradientOrigin="49,87" Center="49,87" MappingMode="Absolute">
<GradientStop Color="{DynamicResource MarinhoMiotec}" Offset="0.27"/>
<GradientStop Color="#FF003052" Offset="0.63"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Viewbox>
</Grid>
This will render the logo in a 50x50 grid cell.

Image reflection in Silverlight 4

I am developing a product scrolling feature where products info( product image, Name, price)will be shown side by side horizontally. i need to show the image of the product and also its reflection. under the reflected image i need to show the Prod Name and its price.
The problem here is i dont want to show the complete reflected image.
the oputput should be something like this
Image Height-100%
Reflected Image Height-20%
Product name
Product Price
The above pattern will repeat horizontally.
I am able to get the desired output with some problem. The reflected image is shown up with hieght 100% and the sapce between the actual image and product name is very high.
My reflected image should be a rotated image of the actual image and only half part of the actual image should be shown.
Sample Code so far..
<ListBox Name="testing" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Image Source="{Binding ImageUrl}" Width="200"/>
<Image Source="{Binding ImageUrl}" Width="200" RenderTransformOrigin="0.5,0.5" Opacity="0.3">
<Image.RenderTransform>
<ScaleTransform ScaleY="-1" ScaleX="1"></ScaleTransform>
</Image.RenderTransform>
<Image.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.5"/>
<GradientStop Color="#FFFFFFFF" Offset="1.0"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" />
<TextBlock Text="{Binding Price}" HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Any pointers even is highly appreciated
For your scale transform, instead of -1, you may want to use a value like .2 since you want it to be 20% the height of the object.
As Jeff points out in order to compress the reflected image to 20% of the originals height you need a ScaleTransform with a ScaleY value of -0.2. The problem is that Render Transforms occur after the layout slot for the element as been allocated. Hence just setting you existing ScaleY value just leaves a 20% height image floating in middle of the same 100% space that the un-transformed image needs.
The Silverlight Toolkit LayoutTransformer control is designed to allow transforms to be applied to content before the layout slot for the control has been allocated. It can then inform its container of the actual space needed post transform.
With this control available change your second (reflected) image element to this:-
<toolkit:LayoutTransformer >
<toolkit:LayoutTransformer.LayoutTransform>
<ScaleTransform ScaleY="-0.2" ScaleX="1" />
</toolkit:LayoutTransformer.LayoutTransform>
<Image Source="Test.png" Width="200" Opacity="0.9">
<Image.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.1"/>
<GradientStop Color="#FFFFFFFF" Offset="1.0"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
</toolkit:LayoutTransformer>
I've tweaked some of the opacity values to make the effect more visible. Now the LayoutTransformer is performing the 20% scale and then reporting to the containing StackPanel the appropriately reduced height requirements.

Resources