Decimal ScrollBar Window with extending IValueConverter : IValueConverter « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » IValueConverterScreenshots 
Decimal ScrollBar Window with extending IValueConverter
Decimal ScrollBar Window with extending IValueConverter
   
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:MyNameSpace.DecimalScrollBar" 
        Title="Decimal ScrollBar">
    <Window.Resources>
        <src:DoubleToDecimalConverter x:Key="conv" />
    </Window.Resources>
    <StackPanel>
        <ScrollBar Name="scroll"
                   Orientation="Horizontal" Margin="24" 
                   Maximum="100" LargeChange="10" SmallChange="1" />
        <Label HorizontalAlignment="Center" 
               Content="{Binding ElementName=scroll, Path=Value, 
                    Converter={StaticResource conv}, ConverterParameter=2}" />
    </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace MyNameSpace.DecimalScrollBar
{
    [ValueConversion(typeof(double), typeof(decimal))]
    public class DoubleToDecimalConverter : IValueConverter
    {
        public object Convert(object value, Type typeTarget,object param, CultureInfo culture)
        {
            decimal num = new Decimal((double)value);

            if (param != null)
                num = Decimal.Round(num, Int32.Parse(param as string));

            return num;
        }
        public object ConvertBack(object value, Type typeTarget, 
                                  object param, CultureInfo culture)
        {
            return Decimal.ToDouble((decimal)value);
        }
    }
}

   
    
    
  
Related examples in the same category
1.IMultiValueConverter and IValueConverterIMultiValueConverter and IValueConverter
2.Extend IValueConverter to create your own converterExtend IValueConverter to create your own converter
3.Debug Data Bindings Using an Empty IValueConverterDebug Data Bindings Using an Empty IValueConverter
4.Use LengthConverterUse LengthConverter
5.Color Converter
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.