Posts Tagged ‘Utilities’
09
Oct

Strip HTML Tags

1 Comment » Popularity: 11%

Corey referred a very useful code snippet provided by John which helps you to strip HTML Tags.

Strip HTML Tags

View Demo: New Window
csharp title:
private string StripHtmlTags(string value){
    int length = 0;
    int.TryParse(value, out length);

    // Remove HTML tags and empty newlines and spaces and leading spaces
    string formattedValue = Regex.Replace(value as string, "<.*?>", "");
    formattedValue = Regex.Replace(formattedValue, @"\n+\s+", "\n\n");
    formattedValue = formattedValue.TrimStart(' ');
    formattedValue = HttpUtility.HtmlDecode(formattedValue);
    if(length > 0 && formattedValue.Length >= length)
        formattedValue = formattedValue.Substring(0, length - 1);
    return formattedValue;
}
29
Sep

Loading Animation

1 Comment » Popularity: 10%

A very simple loading animation in XAML format.

Loading Animation

View Demo: New Window
Create a simple loading in XAML:
<UserControl x:Class="ShineDraw.Controls.LoadingAnimation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="400" >
    <UserControl.Resources>
        <Storyboard x:Name="Rotation" RepeatBehavior="Forever">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="45"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="45"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="90"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="90"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="135"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="135"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.8000000" Value="180"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.0000000" Value="180"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.0000000" Value="225"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.2000000" Value="225"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.2000000" Value="270"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.4000000" Value="270"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.4000000" Value="315"/>
                <SplineDoubleKeyFrame KeyTime="00:00:01.6000000" Value="315"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent" RenderTransformOrigin="0.5,0.5">
        <Grid.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform/>
                <TranslateTransform/>
            </TransformGroup>
        </Grid.RenderTransform>
        <Ellipse Width="100" Height="100" Fill="#FF000000" >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FFAAAAAA" >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="45" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FFAAAAAA"  >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="90" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FFAAAAAA"  >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="135" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FF999999"  >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="180" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FF777777" >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="225" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FF555555"  >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="270" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
        <Ellipse Width="100" Height="100" Fill="#FF333333"  >
            <Ellipse.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="315" CenterX="200" CenterY="50"/>
                    <TranslateTransform X="-150"/>
                </TransformGroup>
            </Ellipse.RenderTransform>
        </Ellipse>
    </Grid>
</UserControl>
26
Sep

Create Gradient Background

Post a comment » Popularity: 1%

Most of the time when you are using Visual Studio and you don’t’ want to open Blend for just setting a very Gradient Background! The below code can surely help you.

Create Gradient Background in XAML

Creat gradient background in c#:
LinearGradientBrush linear = new LinearGradientBrush();
linear.StartPoint = new Point(0.5, 0);
linear.EndPoint = new Point(0.5, 1);

GradientStop g1 = new GradientStop();
g1.Color = _backgroundColor1;
g1.Offset = 0;

GradientStop g2 = new GradientStop();
g2.Color = _backgroundColor2;
g1.Offset = 1;

linear.GradientStops.Add(g2);
linear.GradientStops.Add(g1);

Border border = new Border();
border.Background = linear;
Creating gradient background in xaml:
<UserControl x:Class="GradientBackground.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="600" Height="400">
    <Grid x:Name="LayoutRoot" Background="White">
        <Rectangle Stroke="Black" Height="180" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="285">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Stroke="Black" Height="190" HorizontalAlignment="Left" Margin="10,0,0,10" VerticalAlignment="Bottom" Width="285">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="0.1"/>
                    <GradientStop Color="Black" Offset="0.2"/>
                    <GradientStop Color="White" Offset="0.3"/>
                    <GradientStop Color="Black" Offset="0.4"/>
                    <GradientStop Color="White" Offset="0.5"/>
                    <GradientStop Color="Black" Offset="0.6"/>
                    <GradientStop Color="White" Offset="0.7"/>
                    <GradientStop Color="Black" Offset="0.8"/>
                    <GradientStop Color="White" Offset="0.9"/>
                    <GradientStop Color="Black" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Stroke="Black" Height="180" HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Width="285">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0,0" StartPoint="1,1">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="Red" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Stroke="Black" Height="190" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="285">
            <Rectangle.Fill>
                <RadialGradientBrush>
                    <GradientStop Color="White" Offset="0"/>
                    <GradientStop Color="Black" Offset="1"/>
                </RadialGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</UserControl>
View Demo: New Window
09
Sep

ASCII Table

Post a comment » Popularity: 1%

This utility helps you to figure out the ASCII code of special characters. Very useful when you want to add some special character in your XAML.

ASCII-Table

View Demo: New Window