Paul Stanley
Paul Stanley

Reputation: 2161

XAML ListView Data Bind To DateTime

In my ViewModel I have a

public ObservableCollection<DateTimeOffset> notOnDates
{
    get => _notOnDates;
    set => SetProperty(ref _notOnDates, value);
}

How do bind a ListView control to the ViewModel notOnDates?

ItemsSource="{x:Bind viewModel.notOnDates, Mode=OneWay}">
    <ListView.ItemTemplate>
       <DataTemplate x:DataType="x:Object">
          <TextBlock Text="{x:Bind Converter={StaticResource offConverter}}" />
       </DataTemplate>
    </ListView.ItemTemplate>

This line is throwing "object not supported in UWP"

 <DataTemplate x:DataType="x:Object">

The designer shows markup error but the project builds and runs.

Upvotes: 0

Views: 151

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

If the element of ObservableCollection is DateTimeOffset, you could pass "system:DateTimeOffset" to x:DataType.

<ListView.ItemTemplate>
    <DataTemplate x:DataType="system:DateTimeOffset">
        <TextBlock Text="{x:Bind Converter={StaticResource DateConverter}}"/>
    </DataTemplate>
</ListView.ItemTemplate>

Upvotes: 1

Related Questions