These are chat archives for AvaloniaUI/Avalonia

1st
Jan 2019
Jonas Jermann
@jjermann
Jan 01 19:17
hi to 2019, question: Is there some example/documentation on how to do external resource dictionaries (for e.g. datatemplates)?
Jonas Jermann
@jjermann
Jan 01 19:29
I read that documentation, there is no mention of any separate resource dictionaries.
At the moment I have all datatemplates defined for Window, which makes the main (window) xaml file huge. I would really like to "extract" all datatemplates into a separate file.
(that way they could also be used for other window/etc)
Just use a StyleInclude
Jonas Jermann
@jjermann
Jan 01 20:49
In your example: What would I put into SideBar.xaml?
I have datatemplates
will this work if I put them inSideBar.xaml and load them like this?
Jonas Jermann
@jjermann
Jan 01 21:48
there seems to be a ResourceInclude
Jonas Jermann
@jjermann
Jan 01 22:27

I always get the following error though:

An exception of type 'Portable.Xaml.XamlObjectWriterException' occurred in Avalonia.Markup.Xaml.dll but was not handled in user code: 'Could not convert object 'DataTemplates.xaml' (of type System.String) to {http://schemas.microsoft.com/winfx/2006/xaml}Uri: Invalid URI: The format of the URI could not be determined.'

The dictionary was loaded as follows:

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceInclude Source = "DataTemplates.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

And the content of DataTemplates.xaml looks as follows:

<ResourceDictionary xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:view="clr-namespace:SidiBarrani.View"
    xmlns:vm="clr-namespace:SidiBarrani.ViewModel">

    <view:StringToBitmapConverter x:Key = "StringToBitmapConverter"/>
    <view:DoubleToThicknessConverter x:Key = "DoubleToThicknessConverter"/>
    <view:StringToBrushConverter x:Key = "StringToBrushConverter"/>

    <DataTemplate DataType = "{x:Type vm:CardRepresentation}">
        ...
    </DataTemplate>
    ...
</ResourceDictionary>