In this xaml snippet I tried to specify the ViewModel and the Locator for the x DataType to change the bindings to x:Bind, but unfortunately that doesn't work here. Why can't I simply omit the specification of Source={StaticResource Locator} and address the whole thing via the x DataType, what am I doing wrong?
<DataTemplate x:Key="appointmentTemplate" >
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding CalendarUCView.GridTappedCommand, Source={StaticResource Locator}}"/>
</core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<ListView ItemsSource="{Binding Converter={StaticResource cellModelToEventsConverter}, Mode=TwoWay}"
VerticalAlignment="Top"
Grid.Row="0"
Style="{StaticResource appointmentCellListViewStyle}"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding CalendarUCView.SelectedAppointment, Source={StaticResource Locator}, Mode=TwoWay}">
<Interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding CalendarUCView.ItemTappedCommand, Source={StaticResource Locator}}"/>
</core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</ListView>
<TextBlock HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Grid.Row="1"
Text="{Binding Converter={StaticResource cellModelToDayConverter}, Mode=OneWay}"
Margin="4"/>
</Grid>
</DataTemplate>
I tryed:
<DataTemplate x:Key="appointmentTemplate"
x:DataType="viewModel:CalendarUCViewModel" >
and also:
<DataTemplate x:Key="appointmentTemplate"
x:DataType="locator:CalendarUCView" >
So usually I can do this:
Command="{x:Bind GridTappedCommand}"
instead of that:
Command="{Binding CalendarUCView.GridTappedCommand, Source={StaticResource Locator}}"
Or if I change the x:DataType to the View (x:DataType="local:CalendarUCView") and use in View:
public CalendarUCViewModel Vm
{
get => (CalendarUCViewModel)DataContext;
}
usually can do this:
Command="{x:Bind Vm.GridTappedCommand}"