随笔分类 -  C# Maui编程

以《WPF编程宝典C#2012 第4版》作为参考,使用C# Maui实现。
06 - Controls例子 - ButtonWithShape
摘要:基于自己写的WpfButton,ButtonWithShape.xaml代码如下。 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" x 阅读全文
posted @ 2025-07-03 09:00 dalgleish 阅读(27) 评论(0) 推荐(0)
06 - Controls例子 - ButtonsWithContent
摘要:由于C# Maui是跨平台,所以按钮是没有写PointerOver这个样式的。本例子通过两种方法展示Button的Style修改。 方法一,使用xaml。这个方法,可以看我前面的教程,在App.xaml中添加MyStyles.xaml,然后自定义的按钮样式就可以被所有项目使用了。 <!--Butto 阅读全文
posted @ 2025-07-03 07:47 dalgleish 阅读(12) 评论(0) 推荐(0)
06 - Controls例子 - EmbeddedFont
摘要:大家自行搜索下载Bayern.ttf,放入Resources/Fonts目录中,并且添加下面代码到MauiProgram.cs中。 EmbeddedFont.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ 阅读全文
posted @ 2025-07-01 09:51 dalgleish 阅读(13) 评论(0) 推荐(0)
05 - Multitouch/RoutedEvents例子 - 自己实现Canvas
摘要:文中例子是基于wpf Canvas写的,由于Maui还没有支持Canvas,所以顺手自己写一个。之前写了一个InkCanvas,发现扩展性太差了,这次写这个Canvas,彻底解决扩展性问题,支持自定义碰撞测试等。自己写的碰撞测试,是基于点集碰撞测试,可以处理任何点集,所以大家可以继承Shape类,写 阅读全文
posted @ 2025-06-30 15:23 dalgleish 阅读(153) 评论(0) 推荐(0)
03 - LayoutPanels例子 - ModularContent
摘要:我对TextBox的功能修改了下,动态更新显示和隐藏密码的图标。为了考验大家,各位自己去修改源代码。再次强调下,如果要把自定义控件加入到默认命名空间,一定要调用Shell扩展中的Navigate (源代码在https://www.cnblogs.com/dalgleish/p/18920441)。如 阅读全文
posted @ 2025-06-27 14:31 dalgleish 阅读(28) 评论(0) 推荐(0)
03 - LayoutPanels例子 - 扩展FlexLayout
摘要:写过wpf的,都知道WrapPanel,这个在C# Maui里用FlexLayout实现。为了简化使用,我直接扩展了FlexLayout,增加了HorizontalSpacing和VerticalSpacing属性,这样就和toolkit:DockLayout中的间隔属性功能一样了。 大家可以重命名 阅读全文
posted @ 2025-06-25 14:07 dalgleish 阅读(38) 评论(0) 推荐(0)
03 - LayoutPanels例子 - TextBox
摘要:C# Maui暂时还没有TextBox,因为这个可以通过xaml样式实现,但是为了长期使用,自己写一个TextBox。 定义一个TextEventArgs public class TextEventArgs : EventArgs { public string Text{ get; set; } 阅读全文
posted @ 2025-06-24 14:36 dalgleish 阅读(197) 评论(0) 推荐(0)
03 - LayoutPanels例子 - LocalizableText
摘要:C# Maui的CheckBox暂时没有Label属性,继承Border扩展CheckBox。其次,为了简单,写一个PropertyManager,共用代码,这样以后换肤时,也可以动态修改对应属性。这里先实现一个CornerRadiusProperty的动态修改。 public class Prop 阅读全文
posted @ 2025-06-22 07:21 dalgleish 阅读(24) 评论(1) 推荐(0)
03 - LayoutPanels例子 - TextBoxColumn
摘要:TextBoxColumn.xaml对应代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://sche 阅读全文
posted @ 2025-06-21 15:34 dalgleish 阅读(15) 评论(0) 推荐(0)
03 - LayoutPanels例子 - SimpleInkCanvas
摘要:C# maui暂时没有官方支持InkCanvas,但是不影响,自己实现一个就行了。目前支持画图,选择,移动和删除。同时支持自定义橡皮擦形状,也支持绑定自定义的形状列表。 实现一个Converter类,以后所有的绑定类型转换都在这个类中实现。 using System; using System.Co 阅读全文
posted @ 2025-06-20 14:10 dalgleish 阅读(149) 评论(0) 推荐(1)
03 - LayoutPanels例子 - SimpleCanvas
摘要:过去,wpf都基于Canvas来定位,现在可以用AbsoluteLayout。 SimpleCanvas.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dot 阅读全文
posted @ 2025-06-16 14:30 dalgleish 阅读(23) 评论(0) 推荐(0)
03 - LayoutPanels例子 - DoubleSplitWindow
摘要:基于之前写GridSplitter,完善下另一个例子。 DoubleSplitWindow.xaml对应代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet 阅读全文
posted @ 2025-06-16 14:03 dalgleish 阅读(28) 评论(0) 推荐(0)
03 - LayoutPanels例子 - SplitWindow
摘要:因为C# Maui还没有把GridSplitter加入到正式支持,但是这个也不是很重要,自己实现一个就行了。继承Border可实现多种样式。 GridSplitter.cs代码 using Microsoft.Maui.Controls.Shapes; using System.Collection 阅读全文
posted @ 2025-06-16 13:43 dalgleish 阅读(36) 评论(0) 推荐(1)
03 - LayoutPanels例子 - SimpleGrid
摘要:下面代码,我是放在Shares项目里的Utility文件夹里。 GridLine重写GraphicsView和IDrawable,自动适应大小。 using System; using System.Collections.Generic; using System.Linq; using Syst 阅读全文
posted @ 2025-06-16 07:07 dalgleish 阅读(19) 评论(0) 推荐(0)
03 - LayoutPanels例子 - BasicDialogBox
摘要:更新Shell扩展,新增弹窗功能。https://www.cnblogs.com/dalgleish/p/18920441 BasicDialogBox.xaml代码,简单一个按钮,用于弹出对话框。 <?xml version="1.0" encoding="utf-8" ?> <ContentPa 阅读全文
posted @ 2025-06-15 10:13 dalgleish 阅读(29) 评论(0) 推荐(0)
03 - LayoutPanels例子 - SimpleDock
摘要:之前已经说过,使用MauiCommunityToolkit包了。这里不再累述。 SimpleDock.xaml代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dot 阅读全文
posted @ 2025-06-15 05:07 dalgleish 阅读(24) 评论(0) 推荐(0)
03 - LayoutPanels例子 - SimpleWrap
摘要:SimpleWrap.xaml对应代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas 阅读全文
posted @ 2025-06-15 01:08 dalgleish 阅读(11) 评论(0) 推荐(0)
03 - LayoutPanels例子 - SimpleStack
摘要:SimpleStack.xaml代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas. 阅读全文
posted @ 2025-06-15 00:51 dalgleish 阅读(18) 评论(0) 推荐(0)
03 - LayoutPanels例子
摘要:这个例子里面用Button作为菜单,写了很多例子,我们先把菜单和跳转写好,之后一个例子一个例子添加。 在AppShell.cs中添加 this.Navigate("MauiViews.MauiDemos.Book._03.LayoutPanels"); LayoutPanels.xaml代码 <?x 阅读全文
posted @ 2025-06-14 14:45 dalgleish 阅读(26) 评论(0) 推荐(0)
02 - Xaml2009例子
摘要:AppShell中添加 this.Navigate("MauiViews.MauiDemos.Book._02.Xaml2009"); Xaml2009.xaml代码 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ 阅读全文
posted @ 2025-06-14 10:47 dalgleish 阅读(19) 评论(0) 推荐(0)