Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / WPF

WPF Sliding Controls Collection – Part 1: Sliding Image Control

Rate me:
Please Sign up or sign in to vote.
4.82/5 (14 votes)
5 Jun 2012CPOL7 min read 66.1K   3.8K   40  
The Sliding Image Control is a part of Sliding Controls, a small but useful WPF custom control collection.
/*
 * UserName: Tefik Becirovic 
 * HomePage: www.Becirovic.eu
 * DateTime: 25.01.2012 12:49
 */

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SlidingImageControl.Test
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.Fant);
        }

        public ImageSource ImageSourceFromCode
        {
            get
            {
                double dpi = 96.0;
                int W = 1000, H = 50;
                RenderTargetBitmap rtb = new RenderTargetBitmap(W, H, dpi, dpi, PixelFormats.Pbgra32);

                Pen pen = new Pen();
                pen.Thickness = 3;
                pen.LineJoin = PenLineJoin.Round;
                pen.EndLineCap = PenLineCap.Round;
                pen.Brush = Brushes.DarkMagenta;

                Random rnd = new Random();

                DrawingVisual visual = new DrawingVisual();

                using (DrawingContext dc = visual.RenderOpen())
                {
                    dc.DrawLine(new Pen(Brushes.Black, 1), new Point(0, H / 2), new Point(W, H / 2));
                    for (int x = 0; x < W / 5; x++)
                        dc.DrawLine(pen, new Point(5 * x + 2.5, rnd.Next(1, H - 2)), new Point(5 * x + 2.5, H / 2));
                }

                rtb.Render(visual);
                return rtb;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions