Skip to content

Commit

Permalink
#3 #11: Néhány apróbb javítás, ha nem valid a képernyő akkor jelezzük
Browse files Browse the repository at this point in the history
  • Loading branch information
gplesz committed Dec 28, 2018
1 parent d48c59c commit 7a0596f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 11 deletions.
39 changes: 39 additions & 0 deletions pg.DarkSky.Wpf/Converters/BoolToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace pg.DarkSky.Wpf.Converters
{
[ValueConversion(typeof(bool), typeof(Visibility))]
public sealed class BoolToVisibilityConverter : IValueConverter
{
public Visibility TrueValue { get; set; }
public Visibility FalseValue { get; set; }

public BoolToVisibilityConverter()
{
// set defaults
TrueValue = Visibility.Visible;
FalseValue = Visibility.Collapsed;
}

public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (!(value is bool))
return null;
return (bool)value ? TrueValue : FalseValue;
}

public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (Equals(value, TrueValue))
return true;
if (Equals(value, FalseValue))
return false;
return null;
}
}
}
21 changes: 16 additions & 5 deletions pg.DarkSky.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:vm="clr-namespace:pg.DarkSky.Wpf.ViewModels"
xmlns:helpers="clr-namespace:pg.DarkSky.Wpf.Helpers"
xmlns:helpers="clr-namespace:pg.DarkSky.Wpf.Helpers"
xmlns:converters="clr-namespace:pg.DarkSky.Wpf.Converters"
mc:Ignorable="d"
DataContext="{x:Static vm:ViewModelLocator.MainViewModel }"
MinHeight="450" MinWidth="650"
Title="pg.DarkSky" Height="450" Width="800">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="VisibleIfTrueConverter" />
<BooleanToVisibilityConverter x:Key="VisibleIfTrueConverter"
/>
<converters:BoolToVisibilityConverter x:Key="VisibleIfTrueConverter2"
TrueValue="Visible"
FalseValue="Hidden" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
Expand All @@ -40,11 +45,17 @@
DisplayMemberPath="Name"
SelectedValuePath="Code"
SelectedItem="{Binding SelectedLanguage}"
ToolTip="{DynamicResource MainWindow.SelectableLanguage}" SelectionChanged="CboSelectableLanguage_SelectionChanged"/>
ToolTip="{DynamicResource MainWindow.SelectableLanguage}"/>
<Button Grid.Column="2"
Content="{iconPacks:FeatherIcons Kind=Repeat}"
ToolTip="{DynamicResource MainWindow.RefreshData}"
Command="{Binding RefreshDataCommand}" />
Command="{Binding RefreshDataCommand}" >
<Button.Content>
<Grid>
<Label Content="{iconPacks:FeatherIcons Kind=Repeat}"
Visibility="{Binding IsNotValid, Converter={StaticResource VisibleIfTrueConverter2} }"/>
</Grid>
</Button.Content>
</Button>
</Grid>
<Grid Grid.Row="1"
Visibility="{Binding HasSuccess, Converter={StaticResource VisibleIfTrueConverter} }"
Expand Down
5 changes: 0 additions & 5 deletions pg.DarkSky.Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@ public MainWindow()
{
InitializeComponent();
}

private void CboSelectableLanguage_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{

}
}
}
40 changes: 39 additions & 1 deletion pg.DarkSky.Wpf/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,32 @@ public bool IsBusy
}
}

//Ez pedig a negáltja az egyszerűbb használathoz
public bool IsNotBusy { get { return !IsBusy; } }

private bool _isValid = false;
/// <summary>
/// Jelzi, hogy a képernyőn lévő adatok rendben vannak-e?
/// vagyis a lenyílók és a megjelenített adatok egymáshoz tartoznak-e. Ha nem, akkor
/// false, ha igen, akkor true
/// </summary>
public bool IsValid
{
get { return _isValid; }
set
{
SetProperty(value, ref _isValid);
OnPropertyChanged(nameof(IsNotValid));
}
}

//Ez pedig a negáltja az egyszerűbb használathoz
public bool IsNotValid
{
get { return !IsValid; }
set { }
}

public bool IsWorking
{
get
Expand Down Expand Up @@ -113,6 +137,8 @@ public Language SelectedLanguage
if (SetProperty(value, ref _selectedLanguage))
{
OnSelectedLanguageChanged(SelectedLanguage);
//jelezzük, hogy a képernyőn lévő adatok mér nem ehhez a lenyíló értékhez tartoznak
IsValid = false;
}
}
}
Expand Down Expand Up @@ -169,7 +195,18 @@ private void OnSelectedLanguageChanged(Language selectedLanguage)

#region City Datasource to combobox
private City _selectedCity;
public City SelectedCity { get { return _selectedCity; } set { SetProperty(value, ref _selectedCity); } }
public City SelectedCity
{
get { return _selectedCity; }
set
{
if (SetProperty(value, ref _selectedCity))
{
//jelezzük, hogy a képernyőn lévő adatok mér nem ehhez a lenyíló értékhez tartoznak
IsValid = false;
}
}
}

private ObservableCollection<City> _selectableCity;
public ObservableCollection<City> SelectableCity { get { return _selectableCity; } set { SetProperty(value, ref _selectableCity); } }
Expand Down Expand Up @@ -223,6 +260,7 @@ private async Task RefreshData()
finally
{
IsBusy = false;
IsValid = true;
CommandManager.InvalidateRequerySuggested();
}
}
Expand Down
1 change: 1 addition & 0 deletions pg.DarkSky.Wpf/pg.DarkSky.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converters\BoolToVisibilityConverter.cs" />
<Compile Include="Helpers\ExtendedBinding.cs" />
<Compile Include="Helpers\GlobalStrings.cs" />
<Compile Include="Helpers\IconHelpers.cs" />
Expand Down

0 comments on commit 7a0596f

Please sign in to comment.