Summary

Class:SampleAppPlus.CustomControl
Assembly:SampleAppPlus
File(s):C:\SampleAppPlus\SampleAppPlus\CustomControl.xaml
C:\SampleAppPlus\SampleAppPlus\CustomControl.xaml.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:62
Line coverage:100%
Branch coverage:50%

Metrics

MethodCyclomatic ComplexitySequence CoverageBranch Coverage
.ctor()1100100
OnRender(...)1100100
OnChange(...)1100100
WriteText(...)310066.67
.cctor()1100100
InitializeComponent()2100100

File(s)

C:\SampleAppPlus\SampleAppPlus\CustomControl.xaml

#LineLine coverage
 21<UserControl x:Class="SampleAppPlus.CustomControl"
 2             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 5             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 6             mc:Ignorable="d"
 7             d:DesignHeight="300" d:DesignWidth="300">
 8    <Grid>
 9        <Image x:Name="myImage" />
 10    </Grid>
 11</UserControl>

C:\SampleAppPlus\SampleAppPlus\CustomControl.xaml.cs

#LineLine coverage
 1using System.Globalization;
 2using System.Windows;
 3using System.Windows.Controls;
 4using System.Windows.Media;
 5using System.Windows.Media.Imaging;
 6
 7namespace SampleAppPlus
 8{
 9    /// <summary>
 10    /// Interaction logic for CustomControl.xaml
 11    /// </summary>
 12    public partial class CustomControl : UserControl
 13    {
 214        public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string
 15
 216        public CustomControl()
 217        {
 218            InitializeComponent();
 219        }
 20
 21        public string Message
 22        {
 3923            get { return (string)GetValue(MessageProperty); }
 2424            set { SetValue(MessageProperty, value); }
 25        }
 26
 27        protected override void OnRender(DrawingContext drawingContext)
 228        {
 429            myImage.Source = WriteText(Message); ;
 230        }
 31
 32        private static void OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
 733        {
 734            var current = d as CustomControl;
 735            current.myImage.Source = WriteText((string)e.NewValue);
 736        }
 37
 38        private static RenderTargetBitmap WriteText(string text)
 939        {
 940            DrawingVisual drawingVisual = new DrawingVisual();
 941            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
 942            {
 943                 FormattedText ft = new FormattedText(text ?? string.Empty, CultureInfo.GetCultureInfo("en-us"), FlowDire
 944                drawingContext.DrawText(ft, new Point(0, 0));
 945            }
 946            RenderTargetBitmap bmp = new RenderTargetBitmap(510, 50, 96, 96, PixelFormats.Pbgra32);
 947            bmp.Render(drawingVisual);
 948            return bmp;
 949        }
 50    }
 51}