Problem with data binding image name

TPLindleyTPLindley Member ✭✭
edited May 2019 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?



  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019

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

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

  • TPLindleyTPLindley Member ✭✭




                <controls:GridView x:Name="targetGridView"
                               ItemSelected="{Binding SelectedTarget,Mode=TwoWay}"
                               ItemsSource="{Binding Targets}"
                               MaxColumns="{Binding MaxColumns}"
                               WidthRequest="{Binding WidthRequest}"
                               TileHeight="{Binding TileHeight}">
                            <Grid Margin="5,5,0,0">
                                <Label VerticalTextAlignment="Center"
                                       Text="{Binding Impacts}"
                                <StackLayout Orientation="Vertical">
                                    <Image Source="{Binding TargetName}"
                                       BackgroundColor="{Binding State,Converter={StaticResource SensorStateToBackgroundColorConverter}}"
                                       HeightRequest="{Binding TargetHeight}"
                                       WidthRequest="{Binding TargetWidth}"
                                            <TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped" NumberOfTapsRequired="2"/>
                                    <Label Margin="0,-5,0,0" Text="{Binding Name}" TextColor="Black" FontSize="Medium" HorizontalTextAlignment="Center" VerticalTextAlignment="End"/>


    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.


Sign In or Register to comment.