Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
zdpcdt committed Aug 29, 2023
2 parents 918f927 + 1098a75 commit ee121f4
Show file tree
Hide file tree
Showing 94 changed files with 577 additions and 504 deletions.
4 changes: 2 additions & 2 deletions docs/basics/data/data-binding/compiled-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ If you have compiled bindings enabled in the root node (via `x:CompileBindings="

## Type casting

In some cases the target type of the binding expression cannot be automatically evaluated. In such cases you muss provide an explicite type cast in the binding expression.
In some cases the target type of the binding expression cannot be automatically evaluated. In such cases you must provide an explicite type cast in the binding expression.

```markup
<ItemsRepeater ItemsSource="{Binding MyItems}">
Expand All @@ -121,4 +121,4 @@ In some cases the target type of the binding expression cannot be automatically
</ItemsRepeater>
```

In this case, the button command shall not be bound to the item's `DataContext` but to a command that is defined in the `DataContext`of the `ItemsRepeater`. The single item will be identified using a `CommandParameter` bound to the item's `DataContext`. Therefore, you must specify the type of the "parent" `DataContext` via cast expression `((vm:MyUserControlViewModel)DataContext)`.
In this case, the button command shall not be bound to the item's `DataContext` but to a command that is defined in the `DataContext`of the `ItemsRepeater`. The single item will be identified using a `CommandParameter` bound to the item's `DataContext`. Therefore, you must specify the type of the "parent" `DataContext` via cast expression `((vm:MyUserControlViewModel)DataContext)`.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class MyCustomSlider : Control
}
```

In this example, a custom routed event called `ValueChangedEvent` is defined for the `MyCustomSlider` control. The event is registered using the `RoutedEvent` system, allowing it to be subscribed by users of the control. A CLR event is also defined for concenience, allowing the event to be consumed in manner consistent with standard .NET APIs.
In this example, a custom routed event called `ValueChangedEvent` is defined for the `MyCustomSlider` control. The event is registered using the `RoutedEvent` system, allowing it to be subscribed by users of the control. A CLR event is also defined for convenience, allowing the event to be consumed in manner consistent with standard .NET APIs.

## Further Reading

For more information see the [Routed Events Deep Dive](../../../../concepts/input/routed-events.md)
For more information see the [Routed Events Deep Dive](../../../../concepts/input/routed-events.md)
4 changes: 2 additions & 2 deletions docs/concepts/reactiveui/reactive-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ As a starting point, you can create a simple view like this:
```xml
<StackPanel Margin="20">
<TextBlock Margin="0 5" >User Name</TextBlock>
<TextBox Text="Binding UserName"/>
<Button Margin="0 20" Command="Binding SubmitCommand">Submit</Button>
<TextBox Text="{Binding UserName}"/>
<Button Margin="0 20" Command="{Binding SubmitCommand}">Submit</Button>
</StackPanel>
```

Expand Down
27 changes: 24 additions & 3 deletions docs/concepts/view-locator.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The View Locator is a mechanism in Avalonia that is used to resolve the view (us

## How it works

The View Locator uses naming conventions to map ViewModel types to view types. By default, it strips "ViewModel" from the end of the ViewModel type name, and looks for a type with the same name in the same namespace, but in the corresponding "Views" namespace.
The View Locator uses naming conventions to map ViewModel types to view types. By default, it replaces every occurrence of the string "ViewModel" within the fully-qualified ViewModel type name with "View".

For example, given a ViewModel named `MyApplication.ViewModels.ExampleViewModel`, the View Locator will look for a View named `MyApplication.Views.Example`.
For example, given a ViewModel named `MyApplication.ViewModels.ExampleViewModel`, the View Locator will look for a View named `MyApplication.Views.ExampleView`.

The View Locator is typically used in conjunction with the `DataContext` property, which is used to link a view to its ViewModel.

Expand Down Expand Up @@ -46,8 +46,29 @@ public class ViewLocator : IDataTemplate
}
```

In this example, the View Locator is implemented as an `IDataTemplate`. The `Build` method creates the view for the ViewModel, and the `Match` method checks if the data object is a ViewModel that this locator knows how to handle.
In this example, the View Locator is implemented as an `IDataTemplate`. The `Build` method creates the view for the ViewModel, and the `Match` method checks if the data object is a ViewModel that this locator knows how to handle. If you do not have a `ViewModelBase` class, at a minimum your ViewModel must implement `INotifyPropertyChanged`, and the comparison in `Match` should be changed accordingly.

## Customizing the View Locator

You can customize the View Locator to use different conventions. For example, you might want to look for views in a different assembly, or use a different naming convention. To do this, you can implement your own View Locator by creating a class that implements the `IDataTemplate` interface, and replace the default View Locator with your own.

## Using the View Locator

By default, the View Locator is referenced in App.axaml as a DataTemplate, in the content of the `Application.DataTemplates` XAML tag. Ensure that its appropriate 'using' statement is in the `xmlns:local` property of the Application root tag.

```xaml
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="LearningAvalonia.App"
xmlns:local="using:LearningAvalonia"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
```
2 changes: 1 addition & 1 deletion docs/get-started/test-drive/code-with-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You can check your work using the following conversion table:

- You have now used an event handler to get and set control properties at runtime. You could now try some of these exercises:
- Stop showing the gridlines (easy).
- Stop the user changing the text in the Fahrenheit input by setting the `ReadOnly` attribute (easy).
- Stop the user changing the text in the Fahrenheit input by setting the `IsReadOnly` attribute (easy).
- Calculate the conversion as the user types into the Celsius input (moderate).

:::info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Legend:
| x:Array |||| x:Array isn't supported in UWP. |
| x:Static |||| x:Static could be replaced with x:Bind |
| x:Type |||| |
| x:True |||| |
| x:False |||| |
| Full Markup Extension |||| UWP only implements a subset of the full markup extension support in WPF. This area needs to be expanded upon in the future. |
| Compiled Bindings |||| |

Expand Down
4 changes: 2 additions & 2 deletions docs/guides/data-binding/binding-from-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ For example if you want to listen to changes to your control's `Foo` property yo
```csharp
static MyControl()
{
FooProperty.Changed.AddClassHandler<MyControl>(x => x.FooChanged);
FooProperty.Changed.AddClassHandler<MyControl>(FooChanged);
}

private void FooChanged(AvaloniaPropertyChangedEventArgs e)
private static void FooChanged(MyControl sender, AvaloniaPropertyChangedEventArgs e)
{
// The 'e' parameter describes what's changed.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public Task Start(Visual? from, Visual? to, bool forward,
This example will shrink the old view and then open up the new view vertically.

```csharp
using Avalonia.VisualTree;

public class CustomTransition : IPageTransition
{
/// <summary>
Expand Down Expand Up @@ -86,7 +88,7 @@ public class CustomTransition : IPageTransition
},
Duration = Duration
};
tasks.Add(animation.RunAsync(from, null, cancellationToken));
tasks.Add(animation.RunAsync(from, cancellationToken));
}

if (to != null)
Expand Down Expand Up @@ -120,7 +122,7 @@ public class CustomTransition : IPageTransition
},
Duration = Duration
};
tasks.Add(animation.RunAsync(to, null, cancellationToken));
tasks.Add(animation.RunAsync(to, cancellationToken));
}

await Task.WhenAll(tasks);
Expand All @@ -143,10 +145,10 @@ public class CustomTransition : IPageTransition
/// <remarks>
/// Any one of the parameters may be null, but not both.
/// </remarks>
private static IVisual GetVisualParent(IVisual? from, IVisual? to)
private static Visual GetVisualParent(Visual? from, Visual? to)
{
var p1 = (from ?? to)!.VisualParent;
var p2 = (to ?? from)!.VisualParent;
var p1 = (from ?? to)!.GetVisualParent();
var p2 = (to ?? from)!.GetVisualParent();

if (p1 != null && p2 != null && p1 != p2)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dotnet add package Avalonia.Controls.TreeDataGrid
Or add package reference directly to the project (`.csproj`) file:

```xml
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="0.10.18" />
<PackageReference Include="Avalonia.Controls.TreeDataGrid" Version="11.0.0" />
```

:::warning
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/controls/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ If a child control has its own dimensions these will be obeyed when it is drawn.

You can mix any of the above in the same size definition sequence. For example:

`ColumnDefinitions="300, *, 2*"`
`ColumnDefinitions="200, *, 2*"`

Using full expanded XAML, this is the same as:

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/controls/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ For guidance on how to bind to commands, see [here](../../basics/user-interface/
A menu icon can be displayed by placing an image or a path icon in the `<MenuItem.Icon>` attached property. For example:

```markup
<<MenuItem Header="_Edit">
<MenuItem Header="_Edit">
<MenuItem Header="Copy">
<MenuItem.Icon>
<PathIcon Data="{StaticResource copy_regular}"/>
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/music-store-app/add-and-layout-controls.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Follow this procedure to include the icons file:

```markup
<Application.Styles>
<FluentTheme Mode="Dark"/>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.MusicStore/Icons.axaml" />
</Application.Styles>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ Follow this procedure to style the main window in 'dark' mode:

- Stop the app if it is still running.
- Locate and open the file **App.axaml**.
- In the XAML, change the `Mode` attribute in the element`<FluentTheme>` from light to dark&#x20;
- In the XAML, change the `RequestedThemeVariant` attribute in the `<Application>` element from "Default" to "Dark"&#x20;

```markup
<FluentTheme Mode="Dark"/>
<Application ...
RequestedThemeVariant="Dark">
```

- Now locate and open the **MainWindow.axaml** file in the **/Views** folder.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/music-store-app/return-from-dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Notice you are using `ReactiveCommand` here. This is provided by the _ReactiveUI

Your next step is bind the **Buy Album** button to the reactive command in the music store view model, follow this procedure:

- Locate and open the **MusicStoreView .cs** file. &#x20;
- Locate and open the **MusicStoreView .axaml** file. &#x20;
- Add the data binding `Command="{Binding BuyMusicCommand}"` to the button element.

## Close the Dialog
Expand Down
4 changes: 4 additions & 0 deletions docs/tutorials/music-store-app/searching-for-albums.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,13 @@ Follow this procedure to add the album name and artist name to the tile:

- Locate and open the **AlbumView.asaml** file.&#x20;
- Add the two text block controls with their data bindings, as shown:
- To have compiled binding working, you need to indicate the datatype used in the view : AlbumViewModel.

```xml
<UserControl ...
xmlns:vm="using:Avalonia.MusicStore.ViewModels"
x:DataType="vm:AlbumViewModel" >

<StackPanel Spacing="5" Width="200">
<Border CornerRadius="10" ClipToBounds="True">
<Panel Background="#7FFF22DD">
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/music-store-app/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This tutorial has used an application solution architecture that uses the MVVM p

Application state is kept in the 'top level' view model, and can be persisted to disk. The main window and search dialog are composed from in _Avalonia UI_ window controls, built-in controls and user controls.&#x20;

This tutorial application targets a windowing platform such as _Apple iOS_ or _Windows_.&#x20;
This tutorial application targets a windowing platform such as _Apple Mac OS_ or _Windows_.&#x20;

:::info
To learn more about targeting applications for iOS (Apple) platforms, see [here](../../guides/platforms/ios).
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/todo-list-app/locating-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ In your to do list app, the main window has had its content set to an object tha
For more information about the concepts behind data templates, see [here](../../concepts/templates/).
:::

As no other data templates match, the search will eventually reach the `ViewLocator` in the application data templates element. This will run its checks and if they pass, return an instance of the corresponding view. It your app this will be the to do list view.&#x20;
As no other data templates match, the search will eventually reach the `ViewLocator` in the application data templates element. This will run its checks and if they pass, return an instance of the corresponding view. In your app this will be the to do list view.&#x20;

<div style={{textAlign: 'center'}}>
<img src="/img/gitbook-import/assets/image (45).png" alt=""/>
Expand All @@ -85,6 +85,6 @@ In this way the content of the main window is set to the correct view, based on

Note that the view locator class is included in the project source rather than being part of the _Avalonia UI_ framework itself. This is because using an implementation of the 'convention over configuration' paradigm is an architectural choice for the application developer.

If you do not want to use the view locator (in a diffent app); then remove it from the project and the **App.axaml** file.
If you do not want to use the view locator (in a different app); then remove it from the project and the **App.axaml** file.

On the next page you will learn how to add revealed functionality and actions to the **OK** and **Cancel** buttons.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ description: CONCEPTS
在某些情况下,绑定表达式的目标类型无法自动计算。在这种情况下,您必须在绑定表达式中提供一个明确的类型转换。

```markup
<ItemsRepeater Items="{Binding MyItems}">
<ItemsRepeater ItemsSource="{Binding MyItems}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ Avalonia提供了多种方法来创建自定义控件以满足应用程序的特
自绘控件通常用于表示大部分非交互式的图形元素,不需要进行主题化。
:::

要创建自绘控件,您需要重写控件的`OnRender`方法,并使用低级别的绘制API(例如`DrawingContext`)来定义控件的外观。这种方法可以对控件的每个像素进行精细控制,实现高度个性化的可视化。
要创建自绘控件,您需要重写控件的`Render`方法,并使用低级别的绘制API(例如`DrawingContext`)来定义控件的外观。这种方法可以对控件的每个像素进行精细控制,实现高度个性化的可视化。

创建自绘控件的步骤如下:

1. **定义控件类**:创建一个新的类,该类派生自`Control`。这个类将定义控件的行为和渲染逻辑。

2. **重写OnRender方法**:在控件类中重写`OnRender`方法,并使用`DrawingContext`来绘制控件的内容。
2. **重写Render方法**:在控件类中重写`Render`方法,并使用`DrawingContext`来绘制控件的内容。
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ public class MyCustomSlider : Control

## 进一步阅读

如需更多信息,请参阅[路由事件深入](../../../../concepts/input/routed-events.md)
如需更多信息,请参阅[路由事件深入](../../../../concepts/input/routed-events.md)
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
id: index
title: 创建控件
---

# 创建控件

```mdx-code-block
import {DocsCardList} from '../../../../../../../../src/components/DocsCard';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
<DocsCardList list={useCurrentSidebarCategory().items} />
```
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MyView : UserControl
var topLevel = TopLevel.GetTopLevel(this);

// 启动异步操作以打开对话框。
var file = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerSaveOptions
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Save Text File"
});
Expand Down
Loading

0 comments on commit ee121f4

Please sign in to comment.