c# - 重新设计 UWP 工具包扩展器箭头
问题描述
我正在尝试从 Windows 社区工具包中重新设置 Expander 控件的样式,将默认的“>”符号更改为实心箭头(有点像播放按钮)。按照这个问题中接受的答案,我从 Community Toolkit github repo 复制了默认样式,并将其粘贴到 ResourceDictionary(名为 CustomStyles.xaml)中,然后将FontIcon
Glyph
属性从更改
为
。我在该Page.Resources
部分中引用了该 ResourceDictionary,然后将新样式绑定到 Expander 的HeaderTemplate
属性并带有StaticResource
引用。一切都应该正常工作,但有些事情导致它失败。
抛出的异常也无济于事,因为错误会显示消息Failed to assign to property 'Microsoft.Toolkit.Uwp.UI.Controls.HeaderedContentControl.HeaderTemplate'. The text associated with this error code could not be found.
有人可以帮忙吗?
主页.xaml
<Page
x:Class="SharpFTP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SharpFTP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" MinHeight="40" />
</Grid.RowDefinitions>
<StackPanel x:Name="itemsPanel" Grid.Column="0" Grid.Row="0">
<toolkit:Expander Header="Favorites" ExpandDirection="Down" HeaderTemplate="{StaticResource expanderFullArrowStyle}">
</toolkit:Expander>
<TextBlock Text="Favorites" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="Connected to " Style="{ThemeResource SubtitleTextBlockStyle}" Foreground="LightGray" />
<TextBlock Text=" 10.3.12.128" Style="{ThemeResource SubtitleTextBlockStyle}" Foreground="White"/>
</StackPanel>
<AppBarSeparator Width="{Binding ActualWidth, ElementName=itemsPanel}" Height="2" Foreground="LightGray" />
</StackPanel>
</Grid>
资源字典 XAML
我只包含了修改后的部分,因为完整的样式有 300 行长。完整的默认扩展器样式可以在这里找到
<FontIcon x:Name="Arrow" Margin="12" FontFamily="Segoe MDL2 Assets" FontSize="12"
Glyph="" RenderTransformOrigin="0.5,0.5">
<FontIcon.RenderTransform>
<RotateTransform />
</FontIcon.RenderTransform>
</FontIcon>
解决方案
您的错误的原因应该是类型不匹配。
您修改了 Expender 的默认样式,则expanderFullArrowStyle
不应在HeaderTemplate
. 请试试这个:
<toolkit:Expander Header="Favorites" ExpandDirection="Down" Style="{StaticResource expanderFullArrowStyle}">
</toolkit:Expander>
推荐阅读
- c++ - MsWord API - 如何将表格单元格的内容从一个转移到另一个
- mysql - mysql查询语法错误,在mysql8.0之后不能在UNION之前使用LIMIT?
- python - 带有默认字段的Django模型序列化问题
- ruby-on-rails - 在任何带有Passenger的来源(Bundler::GemNotFound)中都找不到i18n-1.1.1
- ios - 如何分配“UIImage”类型的值?输入“UIView?”
- angular - 使用 Angular 原理图创建新模块
- java - org.springframework.dao.DataIntegrityViolationException on API 调用
- java - 改造抛出错误预期 BEGIN_OBJECT 但 BEGIN_ARRAY 从数组列表到列表?
- android - 如何解决 java.lang.StringIndexOutOfBoundsException?
- sql - Log4net 不会使用 AdoNetAppender MVC 在数据库中注册