Я пытался переместить DataTemplate из ListView в словарь ресурсов, и, как мне кажется, он каким-то образом нарушил привязки.
Я убедился, что при жестком кодировании текста Textblock он отображается в виде списка, и кажется,привязка источника данных listview работает, она просто не может отображать мои данные.
Вот словарь:
<ResourceDictionary
x:Class="Marathon.Resources.ListViewTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Marathon">
<DataTemplate x:Key="LVTemplate" x:DataType="local:Result">
<StackPanel Orientation="Horizontal" Height="Auto" Padding="12" AutomationProperties.Name="{x:Bind ID}">
<TextBlock Text="{x:Bind ToString()}" VerticalAlignment="Center" Style="{ThemeResource BaseTextBlockStyle}" Foreground="White" Margin="12,0,0,0" FontSize="24"/>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
Вот как я ссылаюсь на шаблон:
<ListView Grid.Row="1" ItemsSource="{x:Bind VM.Results}" ItemTemplate="{StaticResource LVTemplate}" Background="#FF343434" >
</ListView>
И вот как это выглядит, когда я помещаю его в шаблон списка вместо словаря:
<ListView Grid.Row="1" ItemsSource="{x:Bind VM.Results}" Background="#FF343434" >
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Result">
<StackPanel Orientation="Horizontal" Height="Auto" Padding="12" AutomationProperties.Name="{x:Bind ID}">
<TextBlock Text="{x:Bind ToString()}" VerticalAlignment="Center" Style="{ThemeResource BaseTextBlockStyle}" Foreground="White" Margin="12,0,0,0" FontSize="24"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Вот скриншоты работы, когда он не находится в ResourceDictionary: ![](https://i.imgur.com/Us7h1J8.png)
И вот оно не работает: ![](https://i.imgur.com/TqlOUZs.png)
Редактировать: Вот мой App.xaml:
<Application
x:Class="Marathon.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Marathon">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/VCenterTextBox.xaml"/>
<ResourceDictionary Source="Resources/KeypadButton.xaml"/>
<ResourceDictionary Source="Resources/ListViewTemplate.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>