Silverlight+RIA Service Required验证失效问题的解决方案

Silverlight+RIA Service当我们给一个Model添加[Required]特性的时候,想必一定是要在内容Save之前进行不能为空的验证。

但是这个验证是基于PropertyChanged的,如果我们不修改内容,而直接提交窗口内容,那么由于没有产生PropertyChanged,所以原先的验证就不会被执行。

示例窗口:

Silverlight+RIA Service Required验证失效问题的解决方案


 1 <UserControl x:Class="SilverlightTest.MainPage"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6     xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
 7     mc:Ignorable="d"
 8     d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded">
 9 
10     <Grid x:Name="LayoutRoot" Background="White">
11         <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
12             <dataInput:ValidationSummary x:Name="vs" Visibility="Visible"></dataInput:ValidationSummary>
13             <StackPanel Orientation="Horizontal" Margin="5">
14                 <TextBlock Text="User Name" Width="100"></TextBlock>
15                 <TextBox x:Name="tbUserName" Width="150" Text="{Binding UserName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}"></TextBox>
16             </StackPanel>
17             <StackPanel Orientation="Horizontal" Margin="5">
18                 <TextBlock Text="User Address" Width="100"></TextBlock>
19                 <TextBox x:Name="tbUserAddress" Text="{Binding UserAddress,Mode=TwoWay}" Width="150"></TextBox>
20             </StackPanel>
21             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
22                 <Button x:Name="btSave" Content="Save" Width="80" Margin="5" Click="btSave_Click"></Button>
23                 <Button x:Name="btCancel" Content="Cancel" Width="80" Margin="5"></Button>
24             </StackPanel>
25         </StackPanel>
26     </Grid>
27 </UserControl>
28 
29 

相关文章:

  • 2022-01-03
  • 2021-06-05
  • 2022-01-18
  • 2021-04-28
  • 2021-12-27
  • 2022-12-23
  • 2022-02-05
猜你喜欢
  • 2022-01-08
  • 2021-12-10
  • 2021-10-09
  • 2022-01-27
  • 2021-12-27
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案