I have the following custom control,
public sealed class MediaFileItemControl : Control
{
public static readonly DependencyProperty MediaFileProperty =
DependencyProperty.Register(nameof(MediaFile), typeof(StorageFile), typeof(MediaFileItemControl), new PropertyMetadata(null));
public MediaFileItemControl()
{
DefaultStyleKey = typeof(MediaFileItemControl);
}
public StorageFile MediaFile
{
get => (StorageFile)GetValue(MediaFileProperty);
set => SetValue(MediaFileProperty, value);
}
}
the following style for it,
<!-- Generic.xaml -->
<Style TargetType="controls:MediaFileItemControl" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:MediaFileItemControl">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{TemplateBinding MediaFile.Name}" />
<TextBlock Text="{TemplateBinding MediaFile.Path}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and lastly, I want to use it within a ListBox, something like:
<ListBox ItemsSource="{x:Bind ViewModel.MediaFiles, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="win_storage:StorageFile" xmlns:win_storage="using:Windows.Storage">
<controls:MediaFileItemControl MediaFile="{x:Bind}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
However, when I build the project, I get the following error in Generic.xaml
The XAML Binary Format (XBF) generator reported syntax error '0x80004005'
Where is the syntax error and what is the right way to achieve what I want?