How to provide the outer glow effect to border?
<Grid Width="200" Height="200">
<Grid.Background>
<RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.8" RadiusY="0.8">
<RadialGradientBrush.GradientStops>
<GradientStop Offset="0" Color="#FF123B5F" />
<GradientStop Offset="1" Color="#FF001F31" />
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
</Grid.Background>
<Border Width="180" Height="180" Margin="10" Background="Transparent"
BorderBrush="White" BorderThickness="1">
<Border.BitmapEffect>
<OuterGlowBitmapEffect GlowColor="White" GlowSize="3" Opacity="1" />
</Border.BitmapEffect>
</Border>
</Grid>
I have tried this but it not working
BitmapEffects are no longer supported in .NET 4.0.
From MSDN
Important In the .NET Framework 4 or later, the BitmapEffect class is
obsolete. If you try to use the BitmapEffect class, you will get an
obsolete exception. The non-obsolete alternative to the BitmapEffect
class is the Effect class. In most situations, the Effect class is
significantly faster.
It isn't the same thing but you can try with a DropShadowEffect with ShadowDepth close to 0 instead.
Example
<Border Width="180" Height="180" Margin="10" Background="Transparent"
BorderBrush="White" BorderThickness="2" Opacity="1.0">
<Border.Effect>
<DropShadowEffect ShadowDepth="0"
Color="White"
Opacity="1"
BlurRadius="5"/>
</Border.Effect>
</Border>
Comparison between the BitmapEffects you had and DropShadowEffect above. DropShadowEffect to the right.
Related
I'm already desperate to find the answer why this happens... here's my code:
ResourceDictionary
<Color x:Key="ControlStrokeColorDefault">#0F000000</Color>
<Color x:Key="ControlStrokeColorSecondary">#29000000</Color>
<LinearGradientBrush x:Key="ControlElevationBorderBrush" MappingMode="Absolute" StartPoint="0,0" EndPoint="0,3">
<LinearGradientBrush.RelativeTransform>
<ScaleTransform CenterY="0.5" ScaleY="-1" />
</LinearGradientBrush.RelativeTransform>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.33" Color="{DynamicResource ControlStrokeColorSecondary}" />
<GradientStop Offset="1.0" Color="{DynamicResource ControlStrokeColorDefault}" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
Panel
<Grid Background="#29000000">
<WrapPanel Background="#F7F7F7" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border Margin="20" Width="100" Height="60" BorderThickness="2" BorderBrush="{DynamicResource ControlElevationBorderBrush}">
<TextBlock>Ok</TextBlock>
</Border>
<Border Margin="20" Width="100" Height="100" BorderThickness="2" BorderBrush="{DynamicResource ControlElevationBorderBrush}">
<TextBlock>???</TextBlock>
</Border>
</WrapPanel>
</Grid>
As a Result, I get that the gradient is calculated only on the first element... is this a wpf bug or am I missing something?
this is because of ScaleY="-1" in ScaleTransform
Scale creates different sizes at different heights
I need to make this shape on a windows phone 8 using XAML:
It is easy to make a rectangle with rounded corners, and the gray background also. But to make the top of the rectangle to be as shown seems very hard. Can someone give me a hint? It's been 2 years since I used XAML, and I am removeing the rust.
nah not really, it's actually pretty simple and there's multiple ways to accomplish the same effect. Here's an example.
<Grid Width="150" Height="200">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border CornerRadius="10,10,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.822,0.633" StartPoint="0.158,0.189">
<GradientStop Color="#FF09CCF4" Offset="0"/>
<GradientStop Color="#FF020CA7" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock Text="Blah" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
</Border>
<Border Grid.Row="1" Background="White" CornerRadius="0,0,10,10"/>
<TextBlock Grid.Row="1" Text="Other Stuff" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
You can trade the Border 's that were used for Rectangle's if you like, hope this helps.
I have a Grid with various child elements like Grid, Stackpanel, Image...Is it possible to round the corners of the grid in a way that crops ALL of the contents? Additionally, the root Grid can vary in size so that cannot be hard coded.
Edit: After a great deal of searching I found that the best solution for this problem is using ClippingBehavior as susggested by #wdavo, thanks! The real problem is not knowing the dimensions of the image. If you know the dimensions then there are many simple out of the box solutions out there.
You can use this clipping behavior
http://expressionblend.codeplex.com/SourceControl/changeset/view/61176#494852
You'll need the Expression Blend SDK installed
<UserControl
x:Class="RoundedCorners.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:behaviors="clr-namespace:Expression.Samples.Interactivity"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="800"
d:DesignWidth="800">
<Grid
x:Name="LayoutRoot"
Background="White"
Margin="50">
<Grid
Background="LightGreen">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<i:Interaction.Behaviors>
<behaviors:ClippingBehavior
CornerRadius="30" />
</i:Interaction.Behaviors>
<Image
Grid.Row="0"
Stretch="Fill"
Source="Image.JPG" />
<StackPanel
Grid.Row="1">
<TextBlock
Text="Hello" />
<TextBlock
Text="World" />
</StackPanel>
</Grid>
</Grid>
You can do that by inserting the grid or stack panel to a border control just like the code below:
<Border CornerRadius="5,5,0,5" BorderThickness="2" BorderBrush="Black" HorizontalAlignment="Center" Width="100" Height="100" VerticalAlignment="Center">
<StackPanel>
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF030FC6" Offset="0.2"/>
</LinearGradientBrush>
</StackPanel.Background>
</StackPanel>
</Border>
<Border CornerRadius="5,5,0,5" BorderThickness="2" BorderBrush="Black" HorizontalAlignment="Left" Width="100" Height="100" VerticalAlignment="Center" Margin="68.833,0,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FFE90D0D" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid/>
</Border>
Im trying to create a stackpanel with a rounded background, that also has a linearbrush from grey to trasparent
I used the ideas exposed here to prevent clipping
http://chriscavanagh.wordpress.com/2008/10/03/wpf-easy-rounded-corners-for-anything/
The problem now is that the text inside the stackpanel also has degradation and then turns invisible
any help?
Similar question
How do I create a WPF Rounded Corner container?
Code:
<Border Margin="235,78,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"
BorderBrush="Red" BorderThickness="1" CornerRadius="8" >
<Grid>
<Border Name="mask" CornerRadius="7">
<Border.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="Gray" Offset="0"/>
<GradientStop Color="Transparent" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<StackPanel Orientation="Horizontal" >
<StackPanel.OpacityMask>
<VisualBrush Visual="{Binding ElementName=mask}"/>
</StackPanel.OpacityMask>
<Image Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />
<TextBlock Foreground="Black" Margin="5,0,3,0" Text="00620"/>
<TextBlock Foreground="Black" Margin="5,0,3,0" Text="Error sincronización" />
</StackPanel>
</Grid>
</Border>
This is due to the OpacityMask, try to remove these lines from your XAML:
<StackPanel.OpacityMask>
<VisualBrush Visual="{Binding ElementName=mask}"/>
</StackPanel.OpacityMask>
And it should work
I have a custom control containing a path that has a templated tooltip. I want to be able to get a reference to a grid in the template at runtime so that I can modify it's children depending on use.
I thought I could use GetTemplateChild to get a reference to the grid in the template from within the OnApplyTemplate method of the control but this method is not firing.
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_tooltipDetails = (Grid)GetTemplateChild("TooltipDetailsGrid");
}
How else might I be able to do this?
Here is the user control's XAML.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="MiX.AssetManagement.UI.Timeline.Silverlight.TimelineBarRibbonItem"
FontSize="9.333" Foreground="White" mc:Ignorable="d">
<UserControl.Resources>
<ControlTemplate x:Key="ToolTipControlTemplateTimelineView" TargetType="ToolTip">
<StackPanel Orientation="Horizontal" Margin="16,0,0,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OpenStates">
<VisualState x:Name="Closed"/>
<VisualState x:Name="Open"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border CornerRadius="4">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#7F000000" Offset="0"/>
<GradientStop Color="#B2000000" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border x:Name="Info" Height="16" Width="16" BorderThickness="2" CornerRadius="8" HorizontalAlignment="Left" VerticalAlignment="Top">
<Border.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#7FFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.BorderBrush>
<Path Fill="White" Stretch="Fill" Margin="5.229,2.089,5.035,2.82" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" Data="M0.77471197,5.0623446 L2.4198356,5.0623446 L2.4198356,10.18 L0.77471197,10.18 z M0.72914064,3.0891075 L2.4654069,3.0891075 L2.4654069,4.3332038 L0.72914064,4.3332038 z">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Border>
<ContentPresenter d:LayoutOverrides="Width, Height" Margin="20,0,0,0"/>
<Grid Grid.Column="1" x:Name="TooltipDetailsGrid">
<TextBlock Text="Tooltip in a Grid"/>
</Grid>
</Grid>
</Border>
</StackPanel>
</ControlTemplate>
</UserControl.Resources>
<Path x:Name="RibbonItem" Cursor="Hand">
<Path.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF66CC33"/>
<GradientStop Color="#FF339900" Offset="1"/>
</LinearGradientBrush>
</Path.Fill>
<ToolTipService.ToolTip>
<ToolTip x:Name="RibbonItemTooltip" Content="" Foreground="#FFFFFFFF" FontSize="9.333" Placement="Mouse" Template="{StaticResource ToolTipControlTemplateTimelineView}"/>
</ToolTipService.ToolTip>
<Path.Data>
<GeometryGroup x:Name="RibbonItemGeometryGroup">
<RectangleGeometry x:Name="RibbonItemBackground" />
</GeometryGroup>
</Path.Data>
</Path>
</UserControl>
You need to be handling code in the ToolTip Classes OnApplyTemplate method. Here is my untested stab at what you need to do:-
Inherit from ToolTip and override the OnApplyTemplate method in this new class:-
public MyToolTip : ToolTip
{
public override void OnApplyTemplate()
{
//Perhaps to stuff
base.OnApplyTemplate();
//Perhaps to other stuff
}
}
In your resources you now set the TargetType to local:MyToolTip and ensure your assembly namespace is placed with the local alias in the user control element.
Now in your Xaml:-
<ToolTipService.ToolTip>
<local:MyToolTip x:Name="RibbonItemTooltip" Content="" Foreground="#FFFFFFFF" FontSize="9.333" Placement="Mouse" Template="{StaticResource ToolTipControlTemplateTimelineView}"/>
</ToolTipService.ToolTip>
I have resolved this in a slightly different way. Rather than modify the template at runtime I have created an instance of the template for each use case. I can then apply the correct template when I create the instance and elements in the template bind to control class to populate the tooltip with the appropriate values.
This is probably a better approach as the structure of the tooltips is now clearly visible in the XAML, rather than being hidden away in the code.