Skip to content

Commit bfdba83

Browse files
committed
Update
1 parent ff7cc61 commit bfdba83

File tree

4 files changed

+21
-85
lines changed

4 files changed

+21
-85
lines changed

src/Files.App/UserControls/DataGridHeader.xaml.cs

Lines changed: 13 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,35 @@
33

44
using Microsoft.UI.Xaml;
55
using Microsoft.UI.Xaml.Controls;
6-
using System.ComponentModel;
76
using System.Runtime.CompilerServices;
87
using System.Windows.Input;
98

109
namespace Files.App.UserControls
1110
{
12-
public sealed partial class DataGridHeader : UserControl, INotifyPropertyChanged
11+
[DependencyProperty<string>("Header")]
12+
[DependencyProperty<bool>("CanBeSorted")]
13+
[DependencyProperty<SortDirection>("ColumnSortOption", "OnColumnSortOptionChanged", IsNullable = true)]
14+
public sealed partial class DataGridHeader : UserControl
1315
{
1416
public ICommand Command { get; set; }
1517
public object CommandParameter { get; set; }
1618

17-
private string header;
18-
19-
public string Header
19+
public void OnColumnSortOptionChanged(SortDirection? oldValue, SortDirection? newValue)
2020
{
21-
get { return header; }
22-
set
23-
{
24-
if (value != header)
21+
VisualStateManager.GoToState(
22+
this,
23+
newValue switch
2524
{
26-
header = value;
27-
NotifyPropertyChanged(nameof(Header));
28-
}
29-
}
30-
}
31-
32-
private bool canBeSorted = true;
33-
34-
public bool CanBeSorted
35-
{
36-
get { return canBeSorted; }
37-
set
38-
{
39-
if (value != canBeSorted)
40-
{
41-
canBeSorted = value;
42-
NotifyPropertyChanged(nameof(CanBeSorted));
43-
}
44-
}
45-
}
46-
47-
private SortDirection? columnSortOption;
48-
49-
public SortDirection? ColumnSortOption
50-
{
51-
get { return columnSortOption; }
52-
set
53-
{
54-
if (value != columnSortOption)
55-
{
56-
switch (value)
57-
{
58-
case SortDirection.Ascending:
59-
VisualStateManager.GoToState(this, "SortAscending", true);
60-
break;
61-
62-
case SortDirection.Descending:
63-
VisualStateManager.GoToState(this, "SortDescending", true);
64-
break;
65-
66-
default:
67-
VisualStateManager.GoToState(this, "Unsorted", true);
68-
break;
69-
}
70-
columnSortOption = value;
71-
}
72-
}
25+
SortDirection.Ascending => "SortAscending",
26+
SortDirection.Descending => "SortDescending",
27+
_ => "Unsorted",
28+
},
29+
true);
7330
}
7431

7532
public DataGridHeader()
7633
{
7734
InitializeComponent();
7835
}
79-
80-
public event PropertyChangedEventHandler PropertyChanged;
81-
82-
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
83-
{
84-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
85-
}
8636
}
8737
}

src/Files.App/UserControls/FolderEmptyIndicator.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</VisualState.StateTriggers>
4040
<VisualState.Setters>
4141
<Setter Target="EmptyText.Visibility" Value="Visible" />
42-
<Setter Target="EmptyText.Text" Value="{x:Bind GetTranslated('NoSearchResultsFound')}" />
42+
<Setter Target="EmptyText.Text" Value="{helpers:ResourceString Name=NoSearchResultsFound}" />
4343
</VisualState.Setters>
4444
</VisualState>
4545
</VisualStateGroup>
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Files.App.Extensions;
5-
using Microsoft.UI.Xaml;
64
using Microsoft.UI.Xaml.Controls;
75

8-
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
9-
106
namespace Files.App.UserControls
117
{
8+
[DependencyProperty<EmptyTextType>("EmptyTextType")]
129
public sealed partial class FolderEmptyIndicator : UserControl
1310
{
14-
public EmptyTextType EmptyTextType
15-
{
16-
get { return (EmptyTextType)GetValue(EmptyTextTypeProperty); }
17-
set { SetValue(EmptyTextTypeProperty, value); }
18-
}
19-
20-
// Using a DependencyProperty as the backing store for EmptyTextType. This enables animation, styling, binding, etc...
21-
public static readonly DependencyProperty EmptyTextTypeProperty =
22-
DependencyProperty.Register("EmptyTextType", typeof(EmptyTextType), typeof(FolderEmptyIndicator), new PropertyMetadata(null));
23-
24-
private string GetTranslated(string resourceName) => resourceName.GetLocalizedResource();
25-
2611
public FolderEmptyIndicator()
2712
{
2813
InitializeComponent();
@@ -35,4 +20,4 @@ public enum EmptyTextType
3520
FolderEmpty,
3621
NoSearchResultsFound,
3722
}
38-
}
23+
}

src/Files.Core.SourceGenerator/Generators/DependencyPropertyGenerator.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Collections.Immutable;
10+
using System.Data.SqlTypes;
1011
using System.Text;
1112

1213
namespace Files.Core.SourceGenerator
@@ -85,7 +86,7 @@ private string EmitSyntaxTree(INamedTypeSymbol typeSymbol, ImmutableArray<Attrib
8586

8687
// Append callback method to PropertyMetadata
8788
if (!string.IsNullOrEmpty(callbackMethodName))
88-
dpPropertyMetadata = EmitDPCallbackParenthesizedLambdaExpression(dpPropertyMetadata, callbackMethodName, type, typeSymbol);
89+
dpPropertyMetadata = EmitDPCallbackParenthesizedLambdaExpression(dpPropertyMetadata, callbackMethodName, type, isNullable, typeSymbol);
8990

9091
// Emit "DependencyProperty.Register(...)" invocation expression
9192
var dpRegisteringExpression = EmitDPRegisterInvocationExpression(propertyName, type, typeSymbol, dpPropertyMetadata);
@@ -123,7 +124,7 @@ private string EmitSyntaxTree(INamedTypeSymbol typeSymbol, ImmutableArray<Attrib
123124
return SyntaxFactory.SyntaxTree(compilationUnit, encoding: Encoding.UTF8).GetText().ToString();
124125
}
125126

126-
private ObjectCreationExpressionSyntax EmitDPCallbackParenthesizedLambdaExpression(ObjectCreationExpressionSyntax expression, string callbackName, ITypeSymbol type, ITypeSymbol classSymbol)
127+
private ObjectCreationExpressionSyntax EmitDPCallbackParenthesizedLambdaExpression(ObjectCreationExpressionSyntax expression, string callbackName, ITypeSymbol type, bool isNullable, ITypeSymbol classSymbol)
127128
{
128129
// (d, e) => ((class)d).callbackName((type)e.OldValue, (type)e.NewValue)
129130
return expression.AddArgumentListArguments(
@@ -144,14 +145,14 @@ private ObjectCreationExpressionSyntax EmitDPCallbackParenthesizedLambdaExpressi
144145
.AddArgumentListArguments(
145146
SyntaxFactory.Argument(
146147
SyntaxFactory.CastExpression(
147-
type.GetTypeSyntax(false),
148+
type.GetTypeSyntax(isNullable),
148149
SyntaxFactory.MemberAccessExpression(
149150
SyntaxKind.SimpleMemberAccessExpression,
150151
SyntaxFactory.IdentifierName("e"),
151152
SyntaxFactory.IdentifierName("OldValue")))),
152153
SyntaxFactory.Argument(
153154
SyntaxFactory.CastExpression(
154-
type.GetTypeSyntax(false),
155+
type.GetTypeSyntax(isNullable),
155156
SyntaxFactory.MemberAccessExpression(
156157
SyntaxKind.SimpleMemberAccessExpression,
157158
SyntaxFactory.IdentifierName("e"),

0 commit comments

Comments
 (0)