8-bank interface and amount verification in the WPF game series

Source: Internet
Author: User

In the previous article "Four user controls of the WPF game series", a list box of items in "My Shop" was created through user controls. This document continues to use the user control to create a bank interface, and verify the validity of the input amount when the user saves money.

1. After creating the control BankElement. xaml, enter the XAML code in it:

<Grid>  <Border BorderThickness="3" CornerRadius="5"              Background="#CEE4E5" BorderBrush="#0C7D42">    <StackPanel Orientation="Vertical" Margin="5"
HorizontalAlignment="Center"> <Image Height="80" Width="80" Margin="5"
Source="{Binding BankImage}"></Image> <TextBlock Name="bankCash" Margin="5"
Text="{Binding BankCash}"></TextBlock> <TextBlock Name="bankInterest" Margin="5"
Text="{Binding BankInterest}"></TextBlock> <TextBlock Name="transferInfo" Margin="5"></TextBlock> <StackPanel Orientation="Horizontal"> <TextBox Name="cashTransfer" Margin="5" Width="100"></TextBox> <Image Name="transImage" Source="image/trans.png" Cursor="Hand" Width="20" Height="20"></Image> </StackPanel> </StackPanel> </Border></Grid>

Style and:

2. After you enter the amount in TextBox, you must first verify the data in two ways:. whether the input amount is a number, B. whether the input amount exceeds the current total amount, and then process the corresponding results.

Private void saveCashImage_MouseLeftButtonDown (object sender, MouseButtonEventArgs e) {Image transferImage = sender as Image; // search for the input amount of TextBox object findCashTextBox = queryGrid. findName ("saveCash"); TextBox saveCashInput = findCashTextBox as TextBox; // find the TextBlock object findCashTextBlock = queryGrid in the feedback result. findName ("saveCashInfo"); TextBlock saveCashInfo = findCashTextBlock as TextBlock; // The current total amount ($750) int remainAmount = Convert. toInt32 (transferImage. tag. toString ());
// Int transAmount;
// Determine whether saveCashInput is a number. Otherwise, transAmout is 0 int. tryParse (saveCashInput. text, out transAmount); // if transAmout is 0, the input data is incorrect. Of course, the input is 0 if (transAmount = 0) {saveCashInfo. text = "Not vaild number";} else {// if the current total amount is exceeded...
If (transAmount> remainAmount) {saveCashInfo. Text = "No enough cash";} else {// Money can be saved to the bank }}}

3. Error message:

To be continued... ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.