Static resources inside TableView using XAML doesn't work

anton.5994anton.5994 ESMember ✭✭
edited June 2014 in Xamarin.Forms

Hi,
There is no way to find a resource defined inside a ContentPage.Resources if you call it from a tag inside a TableView. Maybe I'm doing something wrong but this code doesn't work for me:

      <ContentPage.Resources>
        <ResourceDictionary>
          <x:String x:Key="caption" >Hello there!</x:String>
        </ResourceDictionary>
      </ContentPage.Resources>

    <TableView>                 
        <TableRoot Title="x">
            <TableSection Title="y">
                <TextCell Text="{StaticResource caption}" />
            </TableSection>
        </TableRoot>
    </TableView>

Thanks in advance!

Posts

  • anton.5994anton.5994 ESMember ✭✭

    no solution with XAML for the moment. The solution could be use the x:Name tag and create the binding with the converter using code:

    countryPicker.SetBinding ( Picker.SelectedIndexProperty, u => u.CurrentAddress.id_country, BindingMode.TwoWay, new CountryIdToIndexConverter (), null);

  • RyanWischkaemperRyanWischkaemper USMember, University ✭✭

    I am also getting this exact same problem. Anyone know why this is happening or know if a fix is coming?

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    @anton @RyanWischkaemper‌: It works fine on 1.2.2-pre2, Can you confirm it's fixed for you ?

  • RyanWischkaemperRyanWischkaemper USMember, University ✭✭

    @StephaneDelcroix‌ Upgrading to 1.2.2-pre2 did fix it, but now I get other errors. I get a Xamarin.Forms.Xaml.XamlParseException: Position 57:79. No Property of name Command found error if I try to use a Button with a Command on it (<Button Text="Save" Command="SaveCommand"/>). Have to downgrade back to 1.1.1

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    @RyanWischkaemper‌ I'm confused, how does this

    <Button Text="Save" Command="SaveCommand"/>
    

    works in 1.1.1 ? "SaveCommand" is not an ICommand, it's a string. The most common (but it's not restricted to this) usage for the Button.Command is to bind to it:

    <Button Text="Save" Command="{Binding SaveCommand}" />
    

    I'm really intrigued by this, but I fail to see a bug here. Could you please share more info on what used to work on 1.1.1 and breaks on 1.2.2-pre2 ? (btw, -pre3 was released)

  • RyanWischkaemperRyanWischkaemper USMember, University ✭✭

    @StephaneDelcroix‌ My mistake for not binding the Button.Command - but with v1.1.1 it worked without the binding.

    Working in v1.1.1:

    <StackLayout>
      <TableView Intent="Form" HasUnevenRows="true">
        <TableView.Root>
          <TableSection>
            <!-- other cells here -->
            <ViewCell>
              <ViewCell.View>
                <StackLayout HorizontalOptions="FillAndExpand" Spacing="5">
                  <Button Text="Save" Command="SaveCommand"/>
                </StackLayout>
              </ViewCell.View>
            </ViewCell>
          </TableSection>
        </TableView.Root>
      </TableView>
    </StackLayout>
    

    View model looked like this:

    public class MyViewModel : ViewModelBase
    {
        public ICommand SaveCommand
        {
            get
            {
                return new Command(() => Save());
            }
        }
    }
    

    And that same code would not work in 1.2.2-pre3 (realized it was pre3 after I made my previous post)

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    @RyanWischkaemper‌ it was a bug apparently

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited June 2018

    Deleted

Sign In or Register to comment.