0

我试图引发验证错误: 1. 当用户输入不是数字的美国 MSRP 时,silverlight 在离开字段时显示错误 2. 但是,如果在同一字段中输入负数,则不会显示错误即使指定了明确的范围
我需要更改什么?

另外,作为一个额外的问题,我应该在 XAML 中使用什么来读取值 Display(Name = "My Name is US MSRP:" 而不是明确指定其他内容

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

}

这是 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>
4

1 回答 1

0

http://betaforums.silverlight.net/forums/p/113795/257670.aspx

于 2010-11-12T01:16:10.860 回答