Problem with data binding image name

TPLindleyTPLindley Member ✭✭
edited May 16 in Xamarin.iOS

I have the following XAML code in a view:

<image source="{Binding TargetName}"/>

and in the view model:

public string TargetName => "showtarget.png";

When I run the app this way, it works in UWP/Android but no graphic is displayed in iOS. If I remove the binding and put the name hard coded like:

<image source="showtarget.png"/>

that works in iOS. Why is this a problem, and more impotently, if I need to dynamically change the image (based on state), how would I go about this?

Thanks.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 17

    Test on my side , but it works fine on iOS.

    Could you share us a basic sample to reproduce the issue?

  • TPLindleyTPLindley Member ✭✭

    `
    <ContentPage.Resources>

    </ContentPage.Resources>
    <ContentPage.ToolbarItems>


    </ContentPage.ToolbarItems>

    <ContentPage.Content>
        <Grid>
            <ScrollView>
                <controls:GridView x:Name="targetGridView"
                               ColumnSpacing="10"
                               ItemSelected="{Binding SelectedTarget,Mode=TwoWay}"
                               ItemsSource="{Binding Targets}"
                               MaxColumns="{Binding MaxColumns}"
                               Padding="5"
                               RowSpacing="5"
                               VerticalOptions="Start"
                               WidthRequest="{Binding WidthRequest}"
                               TileHeight="{Binding TileHeight}">
                    <controls:GridView.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="5,5,0,0">
                                <Label VerticalTextAlignment="Center"
                                       HorizontalTextAlignment="Center" 
                                       Text="{Binding Impacts}"
                                       FontSize="Large" 
                                       FontAttributes="Bold"
                                       Margin="0,-5,0,0"/>
                                <StackLayout Orientation="Vertical">
                                    <Image Source="{Binding TargetName}"
                                       BackgroundColor="{Binding State,Converter={StaticResource SensorStateToBackgroundColorConverter}}"
                                       HeightRequest="{Binding TargetHeight}"
                                       WidthRequest="{Binding TargetWidth}"
                                       HorizontalOptions="CenterAndExpand"
                                       VerticalOptions="Center"
                                       Opacity=".65">
                                        <Image.GestureRecognizers>
                                            <TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped" NumberOfTapsRequired="2"/>
                                        </Image.GestureRecognizers>
                                    </Image>
                                    <Label Margin="0,-5,0,0" Text="{Binding Name}" TextColor="Black" FontSize="Medium" HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>
                                </StackLayout>
                            </Grid>
                        </DataTemplate>
                    </controls:GridView.ItemTemplate>
                </controls:GridView>
            </ScrollView>
        </Grid>
    </ContentPage.Content>
    

    `

    Here is the full XAML from the page with the issues. This page does not work, but if I remove '{Binding TargetName}' and replace with 'showtarget.png' that will work.

  • TPLindleyTPLindley Member ✭✭

    On further testing, i created a sample app with the same tabbed view and that all works fine. What I discovered is that the property bound to the image name is not getting called. All the other properties on that page are getting called and working fine. But, the source for that image in this app is not. In my sample app it does get invoked and as I said works fine. So it must be something specific to this app that is causing the problem. The UWP version works as well as the Android.

    I could really use some pointers on where to look for reasons why the property would not get invoked.

    Thanks.

Sign In or Register to comment.