Why don't avalonia save DataTemplate as a .DataTemplate file? #19559
-
If i can save a DataTemplate like
It's more easier, more clear, and can be located directly where something goes wrong. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is already possible. Most (any?) types you define in an Avalonia project can have a XAML file if you simply create a matching .xaml file with a matching MyDataTemplate.axaml.cs using Avalonia.Markup.Xaml.Templates;
namespace AvaloniaSandbox.Shell;
public class MyDataTemplate : DataTemplate { } MyDataTemplate.axaml <DataTemplate
x:Class="AvaloniaSandbox.Shell.MyDataTemplate"
x:DataType="vm:MainWindowViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:vm="using:AvaloniaSandbox.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="{Binding Text}" />
</DataTemplate> Usage : <ContentControl Content="{Binding}">
<ContentControl.ContentTemplate>
<local:MyDataTemplate />
</ContentControl.ContentTemplate>
</ContentControl> Note that this will display the value of |
Beta Was this translation helpful? Give feedback.
This is already possible. Most (any?) types you define in an Avalonia project can have a XAML file if you simply create a matching .xaml file with a matching
x:Class
though it's rarely useful.MyDataTemplate.axaml.cs
MyDataTemplate.axaml
Usage :