0

I'm trying to restyle the Expander control from the Windows Community Toolkit, changing the default ">" symbol to a filled arrow (kind of like a Play button). Following the accepted answer in this question, I copied the default style from the Community Toolkit github repo, and pasted it into a ResourceDictionary (named CustomStyles.xaml), then changed the FontIcon Glyph property from  to . I've referenced that ResourceDictionary in the Page.Resources section, and then bound the new style to the Expander's HeaderTemplate property with a StaticResource reference. Everything should work, but something is causing it to fail.

The exception being thrown is of no help either, as the error displays the message Failed to assign to property 'Microsoft.Toolkit.Uwp.UI.Controls.HeaderedContentControl.HeaderTemplate'. The text associated with this error code could not be found.

Can someone help with this please?

MainPage.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>

ResourceDictionary XAML

I've included only the modified portion as the full style is 300 lines long. The full default Expander style can be found here

    <FontIcon x:Name="Arrow" Margin="12" FontFamily="Segoe MDL2 Assets" FontSize="12"
              Glyph="&#xE937;" RenderTransformOrigin="0.5,0.5">
              <FontIcon.RenderTransform>
                      <RotateTransform />
              </FontIcon.RenderTransform>
    </FontIcon>
Keven M
  • 972
  • 17
  • 47

1 Answers1

0

The cause of your error should be a type mismatch.

You have modified the default style of Expender, then expanderFullArrowStyle should not be used on HeaderTemplate. Please try this:

<toolkit:Expander Header="Favorites" ExpandDirection="Down" Style="{StaticResource expanderFullArrowStyle}">
</toolkit:Expander>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • This did lead me to a (partial) solution, although making that change didn't fix it: The problem was with the TargetType in the ResourceDictionary. I changed both TargetType instances to `toolkit:Expander`, and then the replacement style showed up. Unfortunately, this broke the Expander so that it no longer shows a Header, rotates, or expands anymore. I'm certain this is because it no longer functions as a ToggleButton, but if I leave either of the TargetTypes as a ToggleButton is crashes before Initializing. – Keven M Feb 27 '20 at 13:16
  • What you are showing only seems to be the default style. Can you provide your modified style? – Richard Zhang Feb 28 '20 at 00:12