自定义messagebox

谁是阿瓦隆? (Who is Avalonia?)

In its structure, it is incredibly close to wpf: similar xaml, similar binding. There is even an official tutorial for wpf developers.
在结构上,它非常接近wpf:相似的xaml,相似的绑定。 甚至有WPF开发人员的官方教程 。
Avaloniya is also notable for the fact that on each of the systems it accesses its native interfaces: Win32, MonoMac, X11…
Avaloniya还因其在每个系统上访问其本机接口的事实而著称:Win32,MonoMac,X11…
更新版本中出现了什么 (What appeared in the updated version)
- Support for 13 different message icons. 支持13种不同的消息图标。
- Ability to copy the message body using the Cntrl + C key combination. 可以使用Cntrl + C组合键复制邮件正文。
- Adjust the size of the window to its contents. 将窗口的大小调整为其内容。
- A simplified style system that allows anyone to easily get involved in the development and support of new ones. 简化的样式系统,使任何人都可以轻松地参与新程序的开发和支持。
- Replacing TextBlock with TextBox, now the text in the window can be selected. 用TextBox替换TextBlock,现在可以选择窗口中的文本。
- The architecture itself has been completely redesigned. 该架构本身已被完全重新设计。

Documentation can be found at gitlab .
可以在gitlab上找到文档。
The package itself can be downloaded from nuget .
包本身可以从nuget下载。
让我们谈谈功能 ( Let's talk about the features)
Obviously, if there are comparisons, it will be compared with wpf.
显然,如果有比较,它将与wpf进行比较。
The first thing that catches your eye after the frameworks from ms is the ability to bind commands to methods. Yes, functionally it gives less opportunity, but in response it simplifies the approach to developing a view model.
在ms的框架之后,引起您注意的第一件事是将命令绑定到方法的能力。 是的,从功能上讲,它提供的机会较少,但是作为响应,它简化了开发视图模型的方法。
<Button Command = "{Binding RunTheThing}" CommandParameter = "Hello World">
Do the thing!
</ Button>
public void RunTheThing (string parameter)
{
// Code for executing the command here.
}
Avaloniya is also built using reactive extensions, which allow working with framework events as with first-class objects using the LINQ declarative query syntax — allowing you to write a concise and readable code.
Avaloniya还使用响应式扩展构建,该响应式扩展允许使用LINQ声明性查询语法像第一类对象一样处理框架事件,从而使您可以编写简洁易懂的代码。
But going a little deeper, everything becomes not so rosy and obvious, and the documentation has not been brought to mind yet (but you can help).
但是再深入一点,一切都不会变得那么乐观和明显,并且文档还没有被想到(但是您可以提供帮助)。
绑定到图像 ( Binding to image )
The problem I encountered almost immediately when updating my project was how to display images on my window.
更新项目时,我几乎立即遇到的问题是如何在窗口上显示图像。
First you need to register a directory with images as a resource of avalonia because it is important that the icons are displayed in any user and conveniently packed with whole the code.
首先,您需要将带有图像的目录注册为雪茄的资源,因为将图标显示在任何用户中并方便地打包完整的代码非常重要。
<ItemGroup>
...
<AvaloniaResource Include = "Assets \ *" />
</ ItemGroup>
Now you can easily set the selected image in the image tag.
现在,您可以轻松地在image标签中设置选定的图像。
<Image Source = "/ Assets / error.ico" />
But when using vm Source, images cannot simply be piped to string, but you must use Bitmap.
但是,在使用vm Source时,不能简单地将图像通过管道传递给字符串,而必须使用Bitmap。
<Image Source = "{Binding ImagePath}" />
public Bitmap ImagePath {get; private set; }
And, accordingly, now we need to extract our image from the resources. What you need to use the locator avalonia.
并且,因此,现在我们需要从资源中提取图像。 您需要使用定位器雪茄。
ImagePath = new Bitmap (AvaloniaLocator.Current.GetService <IAssetLoader> ()
.Open (new Uri ($ "avares: // ASSEMBLYNAME / relative / project / path / {ImageName} .ico")));
It should be noted that for embedded resources when compiling uri, the prefix
应该注意的是,对于嵌入资源,在编译uri时,前缀
resm:// ( resm: // )
is used, and for avalonia —
用于雪崩,
阿瓦雷斯:// ( avares: // )
.
。
画画 ( Drawing )
The figures in avalonia and wpf are similar, but the public properties are different. Therefore, after downloading svg images and converting them into ms xaml using inskape, they could not be accessed immediately.
雪崩和wpf中的数字相似,但公共属性不同。 因此,在下载svg图像并将其使用inskape转换为ms xaml之后,无法立即访问它们。
Arbitrary shape
任意形状
<PathGeometry
Figures = "M30 53 C15.641 53 4 41.359 4 27S15.641 1 30 1s26 11.641 26 26c0 7.135-2.874 13.599-7.528 18.297"
FillRule = "NonZero" />
Turns into
变成
<GeometryDrawing
Brush = "# FF50C8EF"
Geometry = "M30 53 C15.641 53 4 41.359 4 27S15.641 1 30 1s26 11.641 26 26c0 7.135-2.874 13.599-7.528 18.297" />
A line
一条线
<Line X1 = "25" Y1 = "37"
X2 = "25" Y2 = "39" StrokeThickness = "2"
Stroke = "# FFFFFFFF"
StrokeMiterLimit = "10"
StrokeStartLineCap = "Round"
StrokeEndLineCap = "Round" />
Turns into
变成
<Line
StartPoint = "25.37"
EndPoint = "25,39"
StrokeThickness = "2"
Stroke = "# FFFFFFFF"
StrokeStartLineCap = "Round"
StrokeEndLineCap = "Round" />
款式 ( Styles )
The styles themselves are sufficiently described in the documentation .
文档中对样式本身进行了充分的描述。
It is worth noting that these are familiar styles with a small admixture of css.
值得注意的是,这些是熟悉的样式,带有少量CSS。
I wanted to show how to apply the style from a separate file.
我想展示如何从单独的文件应用样式。
First, all xaml files must be avalonian resources.
首先,所有xaml文件必须是阿瓦隆资源。
<ItemGroup>
<AvaloniaResource Include = "** \ *. Xaml">
<SubType> Designer </ SubType>
</ AvaloniaResource>
.....
</ ItemGroup>
Secondly, styles are applied in the same way as image resources using uri and locator.
其次,使用uri和locator以与图像资源相同的方式应用样式。
YourControl.Styles.Add (new StyleInclude (new Uri ("avares: //ASSEMBLYNAME/relative/project/path.xaml")) {Source = new Uri ("avares: // ASSEMBLYNAME / relative / project / path.xaml ")});
好东西。 ( Nice little things. )
TextBox has Watermark property
TextBox具有水印属性
That allows not to look for third-party packages and not to fence TextBlock on top of TextBox, which can be read in many tutorials for wpf.
这样就不必寻找第三方程序包,也不能将TextBlock置于TextBox之上,而在很多wpf教程中都可以阅读。
<TextBox Watermark = "Street address" />
As well, all the default binding uses PropertyChanged to trigger the update of the associated property.
同样,所有默认绑定都使用PropertyChanged来触发关联属性的更新。
结论 ( In Conclusion )
I suggest to everyone to try this interesting framework.
我建议所有人尝试这个有趣的框架。
Thanks to users Artyom Gorchakov and Nikita Tsukanov .
感谢用户Artyom Gorchakov和Nikita Tsukanov 。
And I remind you that avalonia has a cozy and amazing support in the Gitter .
我要提醒您,雪茄在Gitter中有舒适而惊人的支持。
自定义messagebox