Projektanker/Icons.Avalonia

<i:Icon/> in template will throw NullReferenceException when set Value

Flithor opened this issue · 1 comments

ControlTemplate and DataTemplate are same.
Example code:

<ContentControl Content="ABCD">
    <!--<ContentControl.Template>
        <ControlTemplate TargetType="ContentControl">
            <Button>
                    <StackPanel>-->
                    <!-- Throw NullReferenceException Here  ↓-->
                    <!--<i:Icon Foreground="Black" Value="fas fa-times" />
                    <TextBlock Text="{TemplateBinding Content}"/>
                </StackPanel>
            </Button>
        </ControlTemplate>
    </ContentControl.Template>-->
    <ContentControl.ContentTemplate>
        <DataTemplate>
             <Button>
                <StackPanel>
                    <!-- Throw NullReferenceException Here  ↓-->
                    <i:Icon Foreground="Black" Value="fas fa-times" />
                    <TextBlock Text="{Binding}"/>
                </StackPanel>
            </Button>
        </DataTemplate>
    </ContentControl.ContentTemplate>
</ContentControl>

Caused by this line:
image
`AvaloniaLocator.Current.GetService()' returns null.

opps.
Reason by my program missing this line.
image

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
        // others
        .WithIcons(container => container
            .Register<FontAwesomeIconProvider>());