界面组件Telerik UI for WPF入门级教程 - 编辑控件模板(一)
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">本文<span style="color: black;">重点</span>演示了<span style="color: black;">怎样</span>提取和编辑Telerik UI for WPF的默认控件模板的两种<span style="color: black;">办法</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;">Telerik UI for WPF官方最新版免费下载试用,历史版本下载,在线文档和<span style="color: black;">帮忙</span>文件下载-慧都网</a></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">从主题XAML文件中手动提取控件模板</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">所有控件<span style="color: black;">拥有</span><span style="color: black;">区别</span>主题的 XAML 文件<span style="color: black;">位置于</span> Themes.Implicit 文件夹中。您<span style="color: black;">能够</span>在 Telerik UI for WPF 安装目录中找到此文件夹,例如 C:\Program Files (x86)\Progress\Telerik UI for WPF R2 2021\Themes.Implicit。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">重视</span></span></strong><span style="color: black;">:从 2021 R2 发布版本<span style="color: black;">起始</span>,文件夹 WPF40 的名<span style="color: black;">叫作</span>更改为 WPF。 文件夹中的 .xaml 文件适用于 .NET Framework 4.0 和 .NET Framework 4.5,引入了一个名为 NetCore 的文件夹,它针对 .NET Core 3.1、.NET 5 和 .NET 6 框架。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">以下示例<span style="color: black;">表示</span><span style="color: black;">怎样</span>为 Office_Black 主题提取 RadListBox 控件模板:</span></p><span style="color: black;">导航到 Telerik UI for WPF 安装目录并打开 Themes.Implicit\WPF\OfficeBlack\Themes 文件夹。您<span style="color: black;">能够</span><span style="color: black;">选取</span> WPF 文件夹中的任何可用主题,文件夹名<span style="color: black;">叫作</span>对应于主题名<span style="color: black;">叫作</span>。</span><span style="color: black;">找到 Telerik.Windows.Controls.xaml 文件并<span style="color: black;">运用</span>您<span style="color: black;">爱好</span>的编辑器打开它。若要<span style="color: black;">查询</span>任何控件的 XAML 文件,您需要<span style="color: black;">晓得</span><span style="color: black;">包括</span>该控件的程序集名<span style="color: black;">叫作</span>,XAML 文件的名<span style="color: black;">叫作</span>对应于程序集的名<span style="color: black;">叫作</span>。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">图 1:导航到所需的 XAML 文件</span></strong></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/6af885a72f694559b5faeab32bc8a0ae~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728356251&x-signature=MKo8lNQ7koqya%2FVvCrmOoay%2FObE%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">重视</span></span></strong><span style="color: black;">:始终从您在应用程序中<span style="color: black;">运用</span>的主题中提取所需的控件模板。例如,<span style="color: black;">倘若</span>您的应用程序<span style="color: black;">运用</span> Office Black 主题,请从 Themes.Implicit\WPF\OfficeBlack\Themes 文件夹中提取控件模板。 <span style="color: black;">每一个</span>主题的控件模板都<span style="color: black;">区别</span>,<span style="color: black;">运用</span>错误的模板可能会<span style="color: black;">引起</span>错误或不良操作。</span></p><span style="color: black;">在编辑器中,找到 RadListBox 控件的默认样式,它被<span style="color: black;">叫作</span>为 RadListBoxStyle。默认样式遵循控件+样式的约定名<span style="color: black;">叫作</span>,例如,RadListBoxStyle。</span><span style="color: black;">在 RadListBoxStyle 下,导航到 Template 属性设置器的值,它指向控件模板。</span><span style="color: black;">从 XAML 文件复制 RadListBox 控件模板。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">复制模板后,您<span style="color: black;">能够</span>修改它并将其应用到控件的单个实例或<span style="color: black;">全部</span>应用程序,<span style="color: black;">办法</span>是创建所需的样式并设置其 Template 属性。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">重视</span></span></strong><span style="color: black;">:更改<span style="color: black;">掌控</span>模板时,您必须<span style="color: black;">包含</span>所有必需的部分。 即使您的代码<span style="color: black;">能够</span>编译,某些功能<span style="color: black;">亦</span>可能会<span style="color: black;">因为</span>省略所需的部分而受到影响,所需部件标有前缀“PART_”。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">要在 RadListBox 控件<span style="color: black;">周边</span>添加圆形红色边框,请<span style="color: black;">根据</span><span style="color: black;">以上</span><span style="color: black;">过程</span>提取控件模板。 <span style="color: black;">而后</span>修改<span style="color: black;">掌控</span>模板,如下面的示例 1 所示。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">示例 1:在 RadListBox 控件<span style="color: black;">周边</span>添加边框</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">XAML</span></p><span style="color: black;"><<span style="color: black;">Application.Resources</span>></span>
<span style="color: black;"><<span style="color: black;">ResourceDictionary</span>></span>
<span style="color: black;"><<span style="color: black;">ResourceDictionary.MergedDictionaries</span>></span>
<span style="color: black;"><<span style="color: black;">ResourceDictionary</span> <span style="color: black;">Source</span>=<span style="color: black;">"/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"</span>/></span>
<span style="color: black;"></<span style="color: black;">ResourceDictionary.MergedDictionaries</span>></span>
<span style="color: black;"><<span style="color: black;">Style</span> <span style="color: black;">BasedOn</span>=<span style="color: black;">"{StaticResource RadListBoxStyle}"</span> <span style="color: black;">TargetType</span>=<span style="color: black;">"telerik:RadListBox"</span>></span><span style="color: black;">
<span style="color: black;"><<span style="color: black;">Setter</span> <span style="color: black;">Property</span>=<span style="color: black;">"Template"</span>></span>
<span style="color: black;"><<span style="color: black;">Setter.Value</span>></span>
<span style="color: black;"><<span style="color: black;">ControlTemplate</span> <span style="color: black;">TargetType</span>=<span style="color: black;">"telerik:RadListBox"</span>></span>
<span style="color: black;"><<span style="color: black;">Grid</span>></span>
<span style="color: black;"><<span style="color: black;">ScrollViewer</span> <span style="color: black;">x:Name</span>=<span style="color: black;">"PART_ScrollViewer"</span>
<span style="color: black;">Margin</span>=<span style="color: black;">"0"</span>
<span style="color: black;">Padding</span>=<span style="color: black;">"{TemplateBinding Padding}"</span>
<span style="color: black;">Bac<span style="color: black;">公斤</span>round</span>=<span style="color: black;">"{TemplateBinding Bac<span style="color: black;">公斤</span>round}"</span>
<span style="color: black;">BorderBrush</span>=<span style="color: black;">"{TemplateBinding BorderBrush}"</span>
<span style="color: black;">BorderThickness</span>=<span style="color: black;">"{TemplateBinding BorderThickness}"</span>
<span style="color: black;">IsTabStop</span>=<span style="color: black;">"False"</span>
<span style="color: black;">HorizontalScrollBarVisibility</span>=<span style="color: black;">"{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"</span>
<span style="color: black;">VerticalScrollBarVisibility</span>=<span style="color: black;">"{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"</span>></span>
<span style="color: black;"><!-- Here is the additional Border --></span>
<span style="color: black;"><<span style="color: black;">Border</span> <span style="color: black;">CornerRadius</span>=<span style="color: black;">"10"</span> <span style="color: black;">BorderBrush</span>=<span style="color: black;">"Red"</span> <span style="color: black;">BorderThickness</span>=<span style="color: black;">"1"</span>></span>
<span style="color: black;"><<span style="color: black;">ItemsPresenter</span>/></span>
<span style="color: black;"></<span style="color: black;">Border</span>></span>
<span style="color: black;"><<span style="color: black;">ScrollViewer.InputBindings</span>></span>
<span style="color: black;"><<span style="color: black;">KeyBinding</span> <span style="color: black;">Command</span>=<span style="color: black;">"telerikPrimitives:ListControl.SelectAllCommand"</span> <span style="color: black;">Key</span>=<span style="color: black;">"A"</span> <span style="color: black;">Modifiers</span>=<span style="color: black;">"Control"</span>/></span>
<span style="color: black;"></<span style="color: black;">ScrollViewer.InputBindings</span>></span>
<span style="color: black;"></<span style="color: black;">ScrollViewer</span>></span>
<span style="color: black;"><<span style="color: black;">ContentPresenter</span> <span style="color: black;">x:Name</span>=<span style="color: black;">"PART_DropVisualPlaceholder"</span> <span style="color: black;">Visibility</span>=<span style="color: black;">"Collapsed"</span> <span style="color: black;">HorizontalAlignment</span>=<span style="color: black;">"Stretch"</span> <span style="color: black;">VerticalAlignment</span>=<span style="color: black;">"Stretch"</span>/></span>
<span style="color: black;"></<span style="color: black;">Grid</span>></span>
<span style="color: black;"></<span style="color: black;">ControlTemplate</span>></span>
<span style="color: black;"></<span style="color: black;">Setter.Value</span>></span>
<span style="color: black;"></<span style="color: black;">Setter</span>></span>
</span><span style="color: black;"></<span style="color: black;">Style</span>></span>
<span style="color: black;"></<span style="color: black;">ResourceDictionary</span>></span>
<span style="color: black;"></<span style="color: black;">Application.Resources</span>></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">图 2:带有红色边框的 RadListBox 控件</span></strong></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/be4667a97ede48898f272a73f4ab1822~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1728356251&x-signature=5Zgx6nc358SuIOO2%2BQIT3p8Xglc%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">Telerik UI for WPF</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">Telerik UI for WPF<span style="color: black;">持有</span>超过100个控件来创建美观、高性能的桌面应用程序,<span style="color: black;">同期</span>还能快速构建企业级办公WPF应用程序。UI for WPF支持MVVM、触摸等,创建的应用程序<span style="color: black;">靠谱</span>且结构良好,非常容易<span style="color: black;">守护</span>,其直观的API将无缝地集成Visual Studio工具箱中。</span></p>
感谢你的精彩评论,带给我新的思考角度。
页:
[1]