https://github.com/noobsoftware/xamlfind
XamlFind lets you Query XAML in Xamarin Forms as well as copying XAML elements.
https://github.com/noobsoftware/xamlfind
c-sharp library querying xamarin-forms xaml
Last synced: 10 days ago
JSON representation
XamlFind lets you Query XAML in Xamarin Forms as well as copying XAML elements.
- Host: GitHub
- URL: https://github.com/noobsoftware/xamlfind
- Owner: noobsoftware
- Created: 2022-10-14T12:56:43.000Z (over 3 years ago)
- Default Branch: Main
- Last Pushed: 2022-10-14T13:13:13.000Z (over 3 years ago)
- Last Synced: 2024-06-14T19:37:51.614Z (about 2 years ago)
- Topics: c-sharp, library, querying, xamarin-forms, xaml
- Language: C#
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# XamlFind
# Nuget Package
https://www.nuget.org/packages/XamlFind/
# To use the base_page class
Make your MainPage inherit from base_page and create a new namespace within your XAML with the name of your assembly for example: xmlns:d="clr-namespace:Player;assembly=Player" for my project with the namespace Player and then set the type of your page to d:base_page instead of ContentPage
# Querying XAML
Querying XAML is done with the underscore function or the find function, taking as parameters the parent XAML element and the query selector.
Currently the selector types that are supported are Element.class or .class or simply Element (Where Element is the name of the element in question and class is the class name and the dot is the query selector for class) StyleId is used to store the class which can be typed within XAML for example as
```
Or by using the add_class method.
```
Selectors can also be chained using the > arrow selector representing the immediate children or the space selector representning all children.
Extra spaces are not allowed so this is an example query selector: ```List elements = this._(".class1>Element.class2 .class3");```
Elements returned must then be cast into the approriate elements to be used for example ```List elements = this._("StackLayout.class1");```
Will return all StackLayouts with class class1
Then to use the StackLayouts do something like this
```
foreach(Element e in elements) {
StackLayout s = (StackLayout)e;
s.BackgroundColor = Color.Red;
}
```
# Copying Elements
```
StackLayout first = new StackLayout();
StackLayout copy = (StackLayout)this.copy(first);
```
# Todos:
- Update to .NET MAUI (Still waiting for AbsoluteLayout to be supported by .NET MAUI)
- Possibly conform better to HTML/CSS standards for example use StyleClass instead of StyleId for classes
- Support more selectors
- Organize code better and remove some functions