Skip to content

Commit

Permalink
Merge pull request microsoft#440 from rchauhan18/fixingSubmitbutton
Browse files Browse the repository at this point in the history
Fix User can Add Product without Item description.
  • Loading branch information
dipeshmsft authored Oct 19, 2022
2 parents a5b2939 + 0d97125 commit df8f6c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
14 changes: 11 additions & 3 deletions Sample Applications/DataBindingDemo/AddProductWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AddProductWindow()
{
InitializeComponent();
}

private void OnInit(object sender, RoutedEventArgs e)
{
DataContext = new AuctionItem("Type your description here",
Expand All @@ -42,9 +42,17 @@ private void SubmitProduct(object sender, RoutedEventArgs e)
{
var automationPeer = UIElementAutomationPeer.CreatePeerForElement(ErrorTextBlock);

if(StartDateEntryForm.Text.Length == 0 || StartPriceEntryForm.Text.Length == 0)
if(StartDateEntryForm.Text.Length == 0 )
{
AnnounceError("Please, fill start date");
}
else if(StartPriceEntryForm.Text.Length == 0)
{
AnnounceError("Please, fill start price");
}
else if(DescriptionEntryForm.Text.Length == 0)
{
AnnounceError("Please, fill both date and start price");
AnnounceError("Please, fill item description");
}
else if (Validation.GetHasError(StartDateEntryForm))
{
Expand Down
17 changes: 14 additions & 3 deletions Sample Applications/DataBindingDemo/AddProductWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@

<TextBlock Grid.Row="1" Grid.Column="0"
Style="{StaticResource SmallTitleStyle}" Margin="0,5,0,5">
Item Description:
Item Description: *
</TextBlock>
<TextBox Name="DescriptionEntryForm" AutomationProperties.Name="Item Description" Grid.Row="1" Grid.Column="1"
Text="{Binding Path=Description, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5" />
AutomationProperties.IsRequiredForForm="True"
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5"
Validation.Error="OnValidationError" >
<TextBox.Text>

<Binding Path="Description" UpdateSourceTrigger="PropertyChanged"
NotifyOnValidationError="True" >
<Binding.ValidationRules>
<ExceptionValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>

<TextBlock Grid.Row="2" Grid.Column="0" Style="{StaticResource SmallTitleStyle}" Margin="0,5,0,5">Start Price: *</TextBlock>

Expand Down
7 changes: 7 additions & 0 deletions Sample Applications/DataBindingDemo/AuctionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace DataBindingDemo
{
Expand Down Expand Up @@ -52,8 +53,14 @@ public string Description
get { return _description; }
set
{

if (string.IsNullOrEmpty(value))
{
throw new ArgumentException("Item description should be added");
}
_description = value;
OnPropertyChanged("Description");

}
}

Expand Down

0 comments on commit df8f6c0

Please sign in to comment.