Skip to content

Commit 3ff8de8

Browse files
authored
Merge pull request #1 from avikeid2007/dev
No changes made to logo.png
2 parents 2c38158 + 6b02616 commit 3ff8de8

File tree

10 files changed

+210
-86
lines changed

10 files changed

+210
-86
lines changed

ClassToXaml.Windows/ClassToXaml.Windows.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
1313
<AppxPackageSigningEnabled>False</AppxPackageSigningEnabled>
1414
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
15-
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
15+
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
1616
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
1717
<GenerateTestArtifacts>True</GenerateTestArtifacts>
1818
<AppxBundle>Never</AppxBundle>

ClassToXaml.Windows/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22

33
<Package
44
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<ApplicationRevision>0</ApplicationRevision>
8+
<ApplicationVersion>1.0.0.*</ApplicationVersion>
9+
<BootstrapperEnabled>True</BootstrapperEnabled>
10+
<Configuration>Release</Configuration>
11+
<CreateWebPageOnPublish>False</CreateWebPageOnPublish>
12+
<GenerateManifests>true</GenerateManifests>
13+
<Install>True</Install>
14+
<InstallFrom>Disk</InstallFrom>
15+
<IsRevisionIncremented>True</IsRevisionIncremented>
16+
<IsWebBootstrapper>False</IsWebBootstrapper>
17+
<MapFileExtensions>True</MapFileExtensions>
18+
<OpenBrowserOnPublish>False</OpenBrowserOnPublish>
19+
<Platform>x64</Platform>
20+
<PublishDir>bin\Release\net8.0-windows10.0.19041.0\win-x64\app.publish\</PublishDir>
21+
<PublishUrl>bin\publish\</PublishUrl>
22+
<PublishProtocol>ClickOnce</PublishProtocol>
23+
<PublishReadyToRun>True</PublishReadyToRun>
24+
<PublishSingleFile>True</PublishSingleFile>
25+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
26+
<SelfContained>True</SelfContained>
27+
<SignatureAlgorithm>(none)</SignatureAlgorithm>
28+
<SignManifests>False</SignManifests>
29+
<SkipPublishVerification>false</SkipPublishVerification>
30+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
31+
<UpdateEnabled>False</UpdateEnabled>
32+
<UpdateMode>Foreground</UpdateMode>
33+
<UpdateRequired>False</UpdateRequired>
34+
<WebPageFileName>Publish.html</WebPageFileName>
35+
</PropertyGroup>
36+
</Project>

ClassToXaml.Windows/Properties/PublishProfiles/win-arm64.pubxml

Lines changed: 0 additions & 25 deletions
This file was deleted.

ClassToXaml/App.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
3636
views.Register(
3737
new ViewMap(ViewModel: typeof(ShellViewModel)),
3838
new ViewMap<MainPage, MainViewModel>(),
39-
new DataViewMap<SecondPage, SecondViewModel, Entity>()
39+
new ViewMap<SecondPage, SecondViewModel>()
4040
);
4141

4242
routes.Register(

ClassToXaml/Assets/logo.png

9.66 KB
Loading

ClassToXaml/Presentation/MainPage.xaml

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,44 @@
2424
Grid.ColumnSpan="2"
2525
Margin="0,0,0,4"
2626
Content="Class To XAML(UWP, WinUI, WPF, MAUI)" />
27-
<ToggleSwitch
28-
x:Name="DarkModeToggle"
27+
<StackPanel
2928
Grid.Column="1"
3029
HorizontalAlignment="Right"
31-
Toggled="OnDarkModeToggleToggled">
32-
<ToggleSwitch.OffContent>
33-
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE708;" />
34-
</ToggleSwitch.OffContent>
35-
<ToggleSwitch.OnContent>
36-
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE706;" />
37-
</ToggleSwitch.OnContent>
38-
</ToggleSwitch>
30+
Orientation="Horizontal">
31+
<ToggleSwitch x:Name="DarkModeToggle" Toggled="OnDarkModeToggleToggled">
32+
<ToggleSwitch.OffContent>
33+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE708;" />
34+
</ToggleSwitch.OffContent>
35+
<ToggleSwitch.OnContent>
36+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE706;" />
37+
</ToggleSwitch.OnContent>
38+
</ToggleSwitch>
39+
<AppBarButton
40+
Command="{x:Bind VM.GoToSecond}"
41+
Icon="Setting"
42+
LabelPosition="Collapsed" />
43+
</StackPanel>
3944
<TextBox
4045
Grid.Row="1"
4146
Margin="8,4"
4247
HorizontalAlignment="Stretch"
4348
VerticalAlignment="Stretch"
4449
AcceptsReturn="True"
45-
PlaceholderText="ClassText"
50+
Header="Class Text( Only Public properties will be use for XAML)"
51+
PlaceholderText="Class Text( Only Public properties will be use for XAML)"
4652
Text="{x:Bind VM.InputText, Mode=TwoWay}" />
53+
<Button
54+
Grid.Row="1"
55+
Margin="8,10"
56+
HorizontalAlignment="Right"
57+
VerticalAlignment="Top"
58+
Command="{x:Bind VM.ExampleCommand}"
59+
Content="Example"
60+
Style="{StaticResource SecondarySmallFabStyle}">
61+
<um:ControlExtensions.Icon>
62+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE943;" />
63+
</um:ControlExtensions.Icon>
64+
</Button>
4765
<Grid
4866
Grid.Row="1"
4967
Grid.RowSpan="3"
@@ -281,15 +299,23 @@
281299
HorizontalAlignment="Stretch"
282300
Command="{x:Bind VM.GenerateCommand}"
283301
Content="Generate XAML"
284-
CornerRadius="4" />
302+
CornerRadius="4">
303+
<um:ControlExtensions.Icon>
304+
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xF133;" />
305+
</um:ControlExtensions.Icon>
306+
</Button>
285307
<Button
286308
Grid.Column="1"
287309
Height="60"
288310
Margin="8,4"
289311
HorizontalAlignment="Stretch"
290312
Command="{x:Bind VM.CopyCommand}"
291313
Content="Copy"
292-
CornerRadius="4" />
314+
CornerRadius="4">
315+
<um:ControlExtensions.Icon>
316+
<SymbolIcon Symbol="Copy" />
317+
</um:ControlExtensions.Icon>
318+
</Button>
293319
<!--<Button
294320
Grid.Column="2"
295321
Height="60"
@@ -305,7 +331,11 @@
305331
HorizontalAlignment="Stretch"
306332
Command="{x:Bind VM.ClearCommand}"
307333
Content="Clear"
308-
CornerRadius="4" />
334+
CornerRadius="4">
335+
<um:ControlExtensions.Icon>
336+
<SymbolIcon Symbol="Delete" />
337+
</um:ControlExtensions.Icon>
338+
</Button>
309339

310340
</Grid>
311341
<TextBox

ClassToXaml/Presentation/MainViewModel.cs

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using System.Text.RegularExpressions;
23

34
using Microsoft.CodeAnalysis;
45
using Microsoft.CodeAnalysis.CSharp;
@@ -19,9 +20,7 @@ public partial class MainViewModel : ObservableObject
1920
public MainViewModel(INavigator navigator)
2021
{
2122
_navigator = navigator;
22-
// Title = "Main";
23-
GoToSecond = new AsyncRelayCommand(GoToSecondView);
24-
NoOfColumn = 1;
23+
NoOfColumn = 2;
2524
IsUseGrid = true;
2625
IsUseTextBlock = false;
2726
IsUseTwoWayBinding = true;
@@ -60,6 +59,15 @@ public MainViewModel(INavigator navigator)
6059
private string? styleForDateTime;
6160
[ObservableProperty]
6261
private string? styleForCombo;
62+
public string placeHolder => @"public class Name
63+
{
64+
public string maiden { get; set; }
65+
public string suffix { get; set; }
66+
public string givenName { get; set; }
67+
public string middleName { get; set; }
68+
public string surname { get; set; }
69+
70+
}";
6371
public RelayCommand GenerateCommand => new RelayCommand(OnGenerateCommandExecuted);
6472
public RelayCommand CopyCommand => new RelayCommand(OnCopyCommandExecuted);
6573
public RelayCommand ClearCommand => new RelayCommand(OnClearCommandExecuted);
@@ -129,12 +137,79 @@ public void GenerateXamlForClass()
129137
{
130138
OutputText = GenerateXamlForClass(InputText, NoOfColumn);
131139
}
140+
private static string ExtractClassName(string classText)
141+
{
142+
// Regular expression to extract class name
143+
string classNamePattern = @"public\s+class\s+(\w+)";
144+
var classNameMatch = Regex.Match(classText, classNamePattern);
145+
146+
if (classNameMatch.Success)
147+
{
148+
return classNameMatch.Groups[1].Value;
149+
}
150+
151+
return string.Empty;
152+
}
153+
private static List<string> ExtractClassDefinitions(string fileContent)
154+
{
155+
List<string> classDefinitions = new List<string>();
156+
string classPattern = @"public\s+class\s+\w+\s*{";
157+
MatchCollection matches = Regex.Matches(fileContent, classPattern);
158+
foreach (Match match in matches)
159+
{
160+
int startIndex = match.Index;
161+
int openBraces = 0;
162+
int endIndex = startIndex;
163+
for (int i = startIndex; i < fileContent.Length; i++)
164+
{
165+
if (fileContent[i] == '{')
166+
{
167+
openBraces++;
168+
}
169+
else if (fileContent[i] == '}')
170+
{
171+
openBraces--;
172+
if (openBraces == 0)
173+
{
174+
endIndex = i;
175+
break;
176+
}
177+
}
178+
}
179+
180+
string classDefinition = fileContent.Substring(startIndex, endIndex - startIndex + 1);
181+
classDefinitions.Add(classDefinition);
182+
}
183+
184+
return classDefinitions;
185+
}
132186
public string GenerateXamlForClass(string classText, int columnCount)
133187
{
134188
if (classText == null)
135189
{
136190
return string.Empty;
137191
}
192+
StringBuilder xamlText = new();
193+
string classPattern = @"public\s+class\s+\w+\s*{";
194+
var classMatches = Regex.Matches(classText, classPattern);
195+
if (classMatches.Count > 1)
196+
{
197+
List<string> classDefinitions = ExtractClassDefinitions(classText);
198+
foreach (string text in classDefinitions)
199+
{
200+
xamlText.AppendLine($" <!--///////////////XAML for class {ExtractClassName(text)}/////////////-->");
201+
xamlText.AppendLine(GenerateXaml(text, columnCount));
202+
}
203+
}
204+
else if (classMatches.Count == 1)
205+
{
206+
return GenerateXaml(classText, columnCount);
207+
}
208+
return xamlText.ToString();
209+
}
210+
211+
private string GenerateXaml(string classText, int columnCount)
212+
{
138213
var properties = GetPublicProperty(classText);
139214
if (properties == null || !properties.Any())
140215
{
@@ -225,7 +300,7 @@ private string AddMargin()
225300
}
226301
return $"Margin=\"{Margin}\"";
227302
}
228-
Dictionary<string, string> typeMap = new(StringComparer.OrdinalIgnoreCase)
303+
private Dictionary<string, string> typeMap = new(StringComparer.OrdinalIgnoreCase)
229304
{
230305
{ "TextBlock", "Label" },
231306
{ "TextBox", "Entry" },
@@ -272,11 +347,7 @@ private void GenerateControlText(int columnCount, StringBuilder xamlBuilder, int
272347
}
273348
}
274349

275-
public ICommand GoToSecond { get; }
276-
277-
private async Task GoToSecondView()
278-
{
279-
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: new Entity(Name!));
280-
}
350+
public ICommand GoToSecond => new AsyncRelayCommand(async () => await _navigator.NavigateViewModelAsync<SecondViewModel>(this));
351+
public ICommand ExampleCommand => new RelayCommand(() => InputText = placeHolder);
281352

282353
}

0 commit comments

Comments
 (0)