Basic Use

Add a reference to CurrencyTextBoxControl.dll from your project, then add the following namespace to your XAML:
xmlns:currency="clr-namespace:CurrencyTextBoxControl;assembly=CurrencyTextBoxControl"
Insert the control like this:
<currency:CurrencyTextBox Number="{Binding Number}" />

Data Validation

Data validation should work the same way WPF's TextBox works:
<currency:CurrencyTextBox Number="{Binding Number, ValidatesOnDataErrors=True}">
    <currency:CurrencyTextBox.Style>
        <Style TargetType="{x:Type currency:CurrencyTextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="FrameworkElement.ToolTip"
                            Value="{Binding RelativeSource={RelativeSource self}, Path=(Validation.Errors).CurrentItem.ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </currency:CurrencyTextBox.Style>
</currency:CurrencyTextBox>

Then make sure the class containing the Number property implements IDataErrorInfo
public string Error
{
    get { throw new System.NotImplementedException(); }
}

public string this[string columnName]
{
    get
    {
        if (columnName == "Number" &&
            (_number < 0 || _number > 10))
        {
            "Number must be between zero and ten.";
        }
        else
        {
            return null;
        }
    }
}

For more details, view the example project included with the source.

Last edited Apr 19, 2012 at 4:08 PM by beoren, version 6

Comments

No comments yet.