levitali / CompiledBindings

MIT License
279 stars 14 forks source link

x:DataType is ignored #29

Open Petrarca181 opened 1 year ago

Petrarca181 commented 1 year ago

Hi, on may MAUI project when I set Datatype x:Bind still thinks datacontext is the base class. How to fix this , thank you.

levitali commented 1 year ago

Can you provide some small sample?

Petrarca181 commented 1 year ago

Sorry, I was not aware that the Intelligence feature is not working , but Resharper was still providing suggestions this confused me. Everything seems to be working fine now.

Petrarca181 commented 1 year ago

But I have another probblem.

  <DatePicker
                Grid.Row="1"
                Grid.Column="3"
                Margin="5"
                Date="{x:Bind ViewModel.SelectedDate , Mode=TwoWay}"
                FontAttributes="Bold"
                FontSize="{markups:OnScreenSize Medium='10',
                                                Large='15',
                                                ExtraLarge='25'}" />
private DateTime _selectedDate;
    public DateTime SelectedDate
    {
        get => _selectedDate;
        set
        {
            SetProperty(ref _selectedDate, value);

        }
    }

I can't compile with error : MSB4018 The "XamlCTask" task failed unexpectedly. System.Xml.XmlException: 'datePicker1' is an unexpected token. Expecting white space. Line 107, position 70.

levitali commented 1 year ago

Thanks for reporting the bug. I will fix it in the next version.

Now, as a workaround, you should either make the {markups:OnScreenSize ... } on one line, or put it on a line before other attributes.

The problem here is, that the XAML is temporary modified during the build, and a x:Name attribute is inserted as the last one. Unfortunately, I didn't test it, when the last attribute is multi-line.

Petrarca181 commented 1 year ago

Thank you, it's working well. I have one final question: Is it against the rules of MVVM to use <TextBox Drop="{x:Bind _viewModel.OnDrop}"/> if I am passing an object and eventargs? Or will they be wrapped elsewhere so that the ViewModel is unaware of the view?

levitali commented 1 year ago

You probably need only the eventargs. Than, I think, it's not again MVVM rules. ViewModel just receives drop data, without "knowing" which View is it.

Petrarca181 commented 1 year ago

I have another problem ( 〃..)

 <ListView
            Grid.Row="1"
            Background="Pink"
            HorizontalOptions="Fill"
            ItemSelected="{x:Bind ViewModel.ItemSelected}"
            ItemsSource="{x:Bind ViewModel.ListItemSource}" 
            >
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="models:PERSONALE">
                    <Label Text="{x:Bind nomeCognome}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
 public void ItemSelected(object sender, SelectedItemChangedEventArgs e) 
 {
  //
 }

Error CS8978 'method group' cannot be made nullable.

levitali commented 1 year ago

Thanks for reporting the bug!

I've fixed it and published a new beta version of CompiledBindings.MAUI nuget.

The problem of the last multi-line attributes is not solved yet. Takes more time.

Petrarca181 commented 1 year ago

Thank you, beta works fine!

Petrarca181 commented 1 year ago

This is really the last one

<CollectionView
                    x:Name="MainView"
                    ItemsSource="{x:Bind ViewModel.ComponentiSquadra, IsItemsSource=True}"
                    MaximumHeightRequest="{x:Bind ViewModel.GetMaxHeight()}">
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <SwipeView>
                                <SwipeView.RightItems>
                                    <SwipeItems Mode="Execute">
                                        <SwipeItem Command="{Binding SwipeItemInvokedCommand, Mode=OneWay}" />
                                    </SwipeItems>
                                </SwipeView.RightItems>
                                <Grid Margin="5">

<SwipeItem Command="{Binding SwipeItemInvokedCommand, Mode=OneWay}" /> I want this to have same BInding Context as "MainView" how?

levitali commented 1 year ago

Try setting Source as MainView. Somethink like this:

<SwipeItem Command="{Binding Source={x:Reference MainView}, Path=BindingContext.SwipeItemInokeCommand}"/>