Skip to content

Commit

Permalink
gggggg
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Oct 22, 2024
1 parent eb895e0 commit 754f458
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Xml namespace
# XAML Essentials

## Importing a namespace

The semantic of `xmlns:x` basically means importing a namespace as an alias named `x`.
Then we can use `:` to access the members of the namespace.
`x:Class` binds the code behind(`.axaml.cs`) the AXAML(not the ViewModel!).

```xml{2,3}
```xml
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication.App"
Expand All @@ -16,13 +16,13 @@ Then we can use `:` to access the members of the namespace.
</Application>
```

## Default xml namespace
## Spreading Namespace

The default namespace is imported without name, which mean its members are imported globally in this AXAML file, we can access them without any prefix.
The default namespace is imported without name, which mean its members are imported globally in this AXAML file, can be accessed them without any prefix.
Generally the default is avalonia namespace which contains built-in components like `Button`, `TextBlock`.

```xml{1}
<Application xmlns="https://github.com/avaloniaui"
```xml
<Application xmlns="https://github.com/avaloniaui" <!-- [!code highlight] -->
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication.App"
xmlns:local="using:AvaloniaApplication"
Expand All @@ -31,20 +31,20 @@ Generally the default is avalonia namespace which contains built-in components l
</Application>
```

## Project namespace
## Import from Project Namespace

`using:AvaloniaApplication` imports the namespace from **specific project**, so `local:` is available to access the types from the project.
`using:<namespace>` imports the namespace from **specific project** with the alias name `local`

```xml{4,8-10}
```xml
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaApplication.App"
xmlns:local="using:AvaloniaApplication"
xmlns:local="using:AvaloniaApplication" <!-- [!code highlight] -->
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.DataTemplates>
<local:ViewLocator/>
<local:ViewLocator/> <!-- use `local` here to access types from it --> <!-- [!code highlight] -->
</Application.DataTemplates>
</Application>
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# MVVM Essentials

```mermaid
graph TD;
Expand Down

0 comments on commit 754f458

Please sign in to comment.