Question

I'm trying to raise validation errors: 1. when the user enter a US MSRP that is not a number, silverlight displays an error when leaving the field 2. However if in the same field I put a negative number, no error is displayed even though there is an explicit range specified
What do I need to change?

Also, as a bonus question, what am I supposed to use in the XAML to read the value Display(Name = "My Name is US MSRP:" rather than explicitly specifying something else

public class CalculatorParameters : INotifyPropertyChanged
{ 
      private double _usMsrp;

    public CalculatorParameters()
    { 
    }


    [Display(Name = "My Name is US MSRP:",
        Description = "The residual value is based on the US MSRP, even with Euro-Delivery")]
    [Range(0, 150000, ErrorMessage = "US MSRP must be a positive amount under $150,000")]
    public double UsMsrp
    {
        get { return _usMsrp; }
        set
        {
            _usMsrp = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("UsMsrp"));
        }
    } 

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

}

And here is the XAML

 <UserControl x:Class="Silverlight.ConfigEnhanced.UcFinance"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:my="clr-namespace:Silverlight.ConfigEnhanced"
         xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       mc:Ignorable="d"
       d:DesignHeight="650" d:DesignWidth="500"  >
        <UserControl.Resources>
            <my:CalculatorParameters x:Key="descriptor"/>
        </UserControl.Resources>
        <df:DataForm x:Name="df1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CurrentItem="{StaticResource descriptor}" CommandButtonsVisibility="None" AutoGenerateFields="False" >
            <df:DataForm.EditTemplate>
                <DataTemplate>
                    <Grid x:Name="LayoutRoot" Background="White">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="160"></RowDefinition>
                            <RowDefinition Height="20"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="270"></RowDefinition> 
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <StackPanel Grid.Row="2" Grid.Column="0">
                            <TextBlock Text="Leasing"  HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"  Margin="0,0,0,15" />
                            <df:DataField Label="Term in Months">
                                <TextBox   Name="txtBoxLeaseTermInMonths" Text="{Binding LeaseTermInMonths, Mode=TwoWay}" GotFocus="RecomputeLease"/>
                            </df:DataField>
                            <df:DataField Label="Down Payment">
                                <TextBox   Name="txtBoxLeaseDownPayment" Text="{Binding LeaseDownPayment, Mode=TwoWay}" GotFocus="RecomputeLease"/>
                            </df:DataField>
                            <df:DataField Label="Money Factor">
                                <TextBox   Name="txtBoxLeaseMoneyFactor" Text="{Binding MoneyFactor, Mode=TwoWay}" GotFocus="RecomputeLease"/>
                            </df:DataField>
                            <df:DataField Label="US MSRP">
                                <TextBox   Name="txtBoxLeaseUsMsrp" Text="{Binding UsMsrp, Mode=TwoWay}" GotFocus="RecomputeLease"/>
                            </df:DataField>
                      </StackPanel>
                    </Grid>
                </DataTemplate>
            </df:DataForm.EditTemplate>
        </df:DataForm>
    </UserControl>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top