Skip to content

Commit

Permalink
Merge pull request microsoft#366 from guimafelipe/fixing-expenseit-demo
Browse files Browse the repository at this point in the history
Fixing bugs 1260528 and 1260525
  • Loading branch information
guimafelipe authored May 10, 2021
2 parents 7b28bcf + bd2c8b0 commit 940ce75
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void addExpenseButton_Click(object sender, RoutedEventArgs e)
var app = Application.Current;
var expenseReport = (ExpenseReport) app.FindResource("ExpenseData");
expenseReport?.LineItems.Add(new LineItem());

DataGridRow row =null;

// Dispatching this at loaded priority so the new row has been added before our code runs
Expand Down Expand Up @@ -82,15 +82,37 @@ private void viewChartButton_Click(object sender, RoutedEventArgs e)
dlg.Show();
}

bool isValid(DependencyObject parent)
{
if (System.Windows.Controls.Validation.GetHasError(parent)) return false;

for(int i = 0; i != VisualTreeHelper.GetChildrenCount(parent); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
if (!isValid(child)) return false;
}

return true;
}

private void okButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"Expense Report Created!",
"ExpenseIt Standalone",
MessageBoxButton.OK,
MessageBoxImage.Information);
if(!isValid(expenseDataGrid1)){
MessageBox.Show(
"Please, fix the errors.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
} else
{
MessageBox.Show(
"Expense Report Created!",
"ExpenseIt Standalone",
MessageBoxButton.OK,
MessageBoxImage.Information);

DialogResult = true;
DialogResult = true;
}
}

private void cancelButton_Click(object sender, RoutedEventArgs e)
Expand Down
22 changes: 16 additions & 6 deletions Sample Applications/ExpenseIt/ExpenseItDemo/LineItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;

namespace ExpenseItDemo
Expand All @@ -11,13 +13,9 @@ public class LineItemCollection : ObservableCollection<LineItem>
{
public event EventHandler LineItemCostChanged;

public new void Add(LineItem item)
public LineItemCollection()
{
if (item != null)
{
item.PropertyChanged += LineItemPropertyChanged;
}
base.Add(item);
CollectionChanged += OnListItemsChanged;
}

private void LineItemPropertyChanged(object sender, PropertyChangedEventArgs e)
Expand All @@ -28,6 +26,18 @@ private void LineItemPropertyChanged(object sender, PropertyChangedEventArgs e)
}
}

private void OnListItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if(e.Action == NotifyCollectionChangedAction.Add)
{
for(int i = 0; i < e.NewItems.Count; i++)
{
LineItem item = e.NewItems[i] as LineItem;
item.PropertyChanged += LineItemPropertyChanged;
}
}
}

private void OnLineItemCostChanged(object sender, EventArgs args)
{
LineItemCostChanged?.Invoke(sender, args);
Expand Down
1 change: 1 addition & 0 deletions Sample Applications/ExpenseIt/ExpenseItDemo/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
<Setter Property="FontFamily" Value="Ariel" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="TextTrimming" Value="WordEllipsis" />
<Setter Property="TextWrapping" Value="WrapWithOverflow" />
<Setter Property="Width" Value="100" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ExpenseItDemo"
DataContext="{StaticResource ExpenseData}"
mc:Ignorable="d"
Title="ViewChartWindow" Height="300" Width="300">
<Grid Style="{StaticResource WindowContentGrid}">
Expand Down

0 comments on commit 940ce75

Please sign in to comment.