Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No changes made to logo.png #1

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ClassToXaml.Windows/ClassToXaml.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxPackageSigningEnabled>False</AppxPackageSigningEnabled>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
Expand Down
2 changes: 1 addition & 1 deletion ClassToXaml.Windows/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>

<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<BootstrapperEnabled>True</BootstrapperEnabled>
<Configuration>Release</Configuration>
<CreateWebPageOnPublish>False</CreateWebPageOnPublish>
<GenerateManifests>true</GenerateManifests>
<Install>True</Install>
<InstallFrom>Disk</InstallFrom>
<IsRevisionIncremented>True</IsRevisionIncremented>
<IsWebBootstrapper>False</IsWebBootstrapper>
<MapFileExtensions>True</MapFileExtensions>
<OpenBrowserOnPublish>False</OpenBrowserOnPublish>
<Platform>x64</Platform>
<PublishDir>bin\Release\net8.0-windows10.0.19041.0\win-x64\app.publish\</PublishDir>
<PublishUrl>bin\publish\</PublishUrl>
<PublishProtocol>ClickOnce</PublishProtocol>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishSingleFile>True</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>True</SelfContained>
<SignatureAlgorithm>(none)</SignatureAlgorithm>
<SignManifests>False</SignManifests>
<SkipPublishVerification>false</SkipPublishVerification>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<UpdateEnabled>False</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateRequired>False</UpdateRequired>
<WebPageFileName>Publish.html</WebPageFileName>
</PropertyGroup>
</Project>
25 changes: 0 additions & 25 deletions ClassToXaml.Windows/Properties/PublishProfiles/win-arm64.pubxml

This file was deleted.

2 changes: 1 addition & 1 deletion ClassToXaml/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
views.Register(
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new DataViewMap<SecondPage, SecondViewModel, Entity>()
new ViewMap<SecondPage, SecondViewModel>()
);

routes.Register(
Expand Down
Binary file added ClassToXaml/Assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 44 additions & 14 deletions ClassToXaml/Presentation/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,44 @@
Grid.ColumnSpan="2"
Margin="0,0,0,4"
Content="Class To XAML(UWP, WinUI, WPF, MAUI)" />
<ToggleSwitch
x:Name="DarkModeToggle"
<StackPanel
Grid.Column="1"
HorizontalAlignment="Right"
Toggled="OnDarkModeToggleToggled">
<ToggleSwitch.OffContent>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE708;" />
</ToggleSwitch.OffContent>
<ToggleSwitch.OnContent>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE706;" />
</ToggleSwitch.OnContent>
</ToggleSwitch>
Orientation="Horizontal">
<ToggleSwitch x:Name="DarkModeToggle" Toggled="OnDarkModeToggleToggled">
<ToggleSwitch.OffContent>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE708;" />
</ToggleSwitch.OffContent>
<ToggleSwitch.OnContent>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE706;" />
</ToggleSwitch.OnContent>
</ToggleSwitch>
<AppBarButton
Command="{x:Bind VM.GoToSecond}"
Icon="Setting"
LabelPosition="Collapsed" />
</StackPanel>
<TextBox
Grid.Row="1"
Margin="8,4"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AcceptsReturn="True"
PlaceholderText="ClassText"
Header="Class Text( Only Public properties will be use for XAML)"
PlaceholderText="Class Text( Only Public properties will be use for XAML)"
Text="{x:Bind VM.InputText, Mode=TwoWay}" />
<Button
Grid.Row="1"
Margin="8,10"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Command="{x:Bind VM.ExampleCommand}"
Content="Example"
Style="{StaticResource SecondarySmallFabStyle}">
<um:ControlExtensions.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE943;" />
</um:ControlExtensions.Icon>
</Button>
<Grid
Grid.Row="1"
Grid.RowSpan="3"
Expand Down Expand Up @@ -281,15 +299,23 @@
HorizontalAlignment="Stretch"
Command="{x:Bind VM.GenerateCommand}"
Content="Generate XAML"
CornerRadius="4" />
CornerRadius="4">
<um:ControlExtensions.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xF133;" />
</um:ControlExtensions.Icon>
</Button>
<Button
Grid.Column="1"
Height="60"
Margin="8,4"
HorizontalAlignment="Stretch"
Command="{x:Bind VM.CopyCommand}"
Content="Copy"
CornerRadius="4" />
CornerRadius="4">
<um:ControlExtensions.Icon>
<SymbolIcon Symbol="Copy" />
</um:ControlExtensions.Icon>
</Button>
<!--<Button
Grid.Column="2"
Height="60"
Expand All @@ -305,7 +331,11 @@
HorizontalAlignment="Stretch"
Command="{x:Bind VM.ClearCommand}"
Content="Clear"
CornerRadius="4" />
CornerRadius="4">
<um:ControlExtensions.Icon>
<SymbolIcon Symbol="Delete" />
</um:ControlExtensions.Icon>
</Button>

</Grid>
<TextBox
Expand Down
91 changes: 81 additions & 10 deletions ClassToXaml/Presentation/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Text.RegularExpressions;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand All @@ -19,9 +20,7 @@ public partial class MainViewModel : ObservableObject
public MainViewModel(INavigator navigator)
{
_navigator = navigator;
// Title = "Main";
GoToSecond = new AsyncRelayCommand(GoToSecondView);
NoOfColumn = 1;
NoOfColumn = 2;
IsUseGrid = true;
IsUseTextBlock = false;
IsUseTwoWayBinding = true;
Expand Down Expand Up @@ -60,6 +59,15 @@ public MainViewModel(INavigator navigator)
private string? styleForDateTime;
[ObservableProperty]
private string? styleForCombo;
public string placeHolder => @"public class Name
{
public string maiden { get; set; }
public string suffix { get; set; }
public string givenName { get; set; }
public string middleName { get; set; }
public string surname { get; set; }

}";
public RelayCommand GenerateCommand => new RelayCommand(OnGenerateCommandExecuted);
public RelayCommand CopyCommand => new RelayCommand(OnCopyCommandExecuted);
public RelayCommand ClearCommand => new RelayCommand(OnClearCommandExecuted);
Expand Down Expand Up @@ -129,12 +137,79 @@ public void GenerateXamlForClass()
{
OutputText = GenerateXamlForClass(InputText, NoOfColumn);
}
private static string ExtractClassName(string classText)
{
// Regular expression to extract class name
string classNamePattern = @"public\s+class\s+(\w+)";
var classNameMatch = Regex.Match(classText, classNamePattern);

if (classNameMatch.Success)
{
return classNameMatch.Groups[1].Value;
}

return string.Empty;
}
private static List<string> ExtractClassDefinitions(string fileContent)
{
List<string> classDefinitions = new List<string>();
string classPattern = @"public\s+class\s+\w+\s*{";
MatchCollection matches = Regex.Matches(fileContent, classPattern);
foreach (Match match in matches)
{
int startIndex = match.Index;
int openBraces = 0;
int endIndex = startIndex;
for (int i = startIndex; i < fileContent.Length; i++)
{
if (fileContent[i] == '{')
{
openBraces++;
}
else if (fileContent[i] == '}')
{
openBraces--;
if (openBraces == 0)
{
endIndex = i;
break;
}
}
}

string classDefinition = fileContent.Substring(startIndex, endIndex - startIndex + 1);
classDefinitions.Add(classDefinition);
}

return classDefinitions;
}
public string GenerateXamlForClass(string classText, int columnCount)
{
if (classText == null)
{
return string.Empty;
}
StringBuilder xamlText = new();
string classPattern = @"public\s+class\s+\w+\s*{";
var classMatches = Regex.Matches(classText, classPattern);
if (classMatches.Count > 1)
{
List<string> classDefinitions = ExtractClassDefinitions(classText);
foreach (string text in classDefinitions)
{
xamlText.AppendLine($" <!--///////////////XAML for class {ExtractClassName(text)}/////////////-->");
xamlText.AppendLine(GenerateXaml(text, columnCount));
}
}
else if (classMatches.Count == 1)
{
return GenerateXaml(classText, columnCount);
}
return xamlText.ToString();
}

private string GenerateXaml(string classText, int columnCount)
{
var properties = GetPublicProperty(classText);
if (properties == null || !properties.Any())
{
Expand Down Expand Up @@ -225,7 +300,7 @@ private string AddMargin()
}
return $"Margin=\"{Margin}\"";
}
Dictionary<string, string> typeMap = new(StringComparer.OrdinalIgnoreCase)
private Dictionary<string, string> typeMap = new(StringComparer.OrdinalIgnoreCase)
{
{ "TextBlock", "Label" },
{ "TextBox", "Entry" },
Expand Down Expand Up @@ -272,11 +347,7 @@ private void GenerateControlText(int columnCount, StringBuilder xamlBuilder, int
}
}

public ICommand GoToSecond { get; }

private async Task GoToSecondView()
{
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: new Entity(Name!));
}
public ICommand GoToSecond => new AsyncRelayCommand(async () => await _navigator.NavigateViewModelAsync<SecondViewModel>(this));
public ICommand ExampleCommand => new RelayCommand(() => InputText = placeHolder);

}
Loading
Loading