Skip to content

VerifyCode

闫驚鏵(Jinhua Yan) edited this page Jul 9, 2023 · 3 revisions

1)Xaml

 <Grid Margin="10">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Button Style="{StaticResource WD.SuccessPrimaryButton}" 
            VerticalAlignment="Center"
            HorizontalAlignment="Center"
            Click="Button_Click"
            Content="获取"/>
    <UniformGrid Rows="2" Columns="2" Grid.Row="1">
        <wd:VerifyCode Foreground="LimeGreen" Name="VerifyCode1"/>
        <wd:VerifyCode Foreground="Red" Name="VerifyCode2"/>
        <wd:VerifyCode Foreground="DodgerBlue" Name="VerifyCode3"/>
        <wd:VerifyCode Foreground="HotPink" Name="VerifyCode4"/>
    </UniformGrid>
  </Grid>

2)CSharp

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        var stringBuilder = new StringBuilder();
        stringBuilder.AppendLine($"获取到验证码如下:");
        stringBuilder.AppendLine(VerifyCode1.VerifyCodeText);
        stringBuilder.AppendLine(VerifyCode2.VerifyCodeText);
        stringBuilder.AppendLine(VerifyCode3.VerifyCodeText);
        stringBuilder.AppendLine(VerifyCode4.VerifyCodeText);
        WPFDevelopers.Controls.MessageBox.Show(stringBuilder.ToString(),
            "验证码",
            System.Windows.MessageBoxButton.OK,
            System.Windows.MessageBoxImage.Information);
    }
Clone this wiki locally