I don't know why I don't see the icon's that has been passing through

KhosrouKhosrou Member ✭✭✭
edited July 2018 in Xamarin.Forms

hi Guys,

I'll try to make my question simpel:

I have a page where you can switch a bunch of things on (like airco, wifi) and the switched on things must be passed to the nextpage and be shown as a icon. For some reason it fills the space but I don't see the icon's, maybe I miss something. Can somebody help me out? I have a viewmodel where I have implemented this

ImageSource GetVoorzieningIcon(FacilityType type)
        {
            switch (type)
            {
                case FacilityType.WiFi:
                    {
                        return ImageSource.FromResource("Images.wifi.png");
                    }
                case FacilityType.Bathroom:
                    {
                        return ImageSource.FromResource("Images.bathtub.png");
                    }
                case FacilityType.Kitchen:
                    {
                        return ImageSource.FromResource("Images.kitchen.png");
                    }
                case FacilityType.Breakfast:
                    {
                        return ImageSource.FromResource("Images.breakfast.png");
                    }
                case FacilityType.Elevator:
                    {
                        return ImageSource.FromResource(".Images.tv.png");
                    }
                case FacilityType.Airco:
                    {
                        return ImageSource.FromResource(".Images.airco.png");
                    }
                case FacilityType.Heating:
                    {
                        return ImageSource.FromResource(".Images.Verwarming.png");
                    }

                default:
                    break;
            }
            return null;

And this is the page where it must be shown

    <Grid 
                        x:Name="VoorzieningenGrid"
                        Padding="0,5,0,0"
                        HorizontalOptions="FillAndExpand"
                        VerticalOptions="FillAndExpand">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                    </Grid>

Best Answer

Answers

  • LarsNymandLarsNymand DKMember ✭✭

    I think there are some code missing here?
    On the first page you are getting an ImageSource object (which I guess you already checked is not null).
    And you show a grid which is on page 2, correct?

    Hows the code for sending ImageSource to page 2?
    Hows the code for inserting the image into the Grid?

  • KhosrouKhosrou Member ✭✭✭

    @LarsNymand The code for inserting the image into the Grid

    private void SetVoorzieningen()
            {
                var voorzieningen = _kamverViewModel.GetVoorzieningen(Kamer);
    
                for (int i = 0; i < voorzieningen.Count; i++)
                {
                    if (i < 4)
                    {
                        VoorzieningenGrid.Children.Add(voorzieningen.ElementAt(i), i, 0);
                    }
                    else
                    {
                        VoorzieningenGrid.Children.Add(voorzieningen.ElementAt(i), i - 4, 1);
                    }
                }
            }
    
  • LarsNymandLarsNymand DKMember ✭✭

    Ahh okay I think you miss the Image. You are trying to insert the ImageSource directly, but that has no view.

    You need something like:

    private void SetVoorzieningen()
    {
        var voorzieningen = _kamverViewModel.GetVoorzieningen(Kamer);
    
        for (int i = 0; i < voorzieningen.Count; i++)
        {
            if (i < 4)
            {
                var image = new Image();
                image.Source = voorzieningen.ElementAt(i);
                VoorzieningenGrid.Children.Add(image, i, 0);
            }
            else
            {
                var image = new Image();
                image.Source = voorzieningen.ElementAt(i);
                VoorzieningenGrid.Children.Add(image, i - 4, 1);
            }
        }
    }
    
  • KhosrouKhosrou Member ✭✭✭

    @LarsNymand If I try that then I'll get this error

    how can I solve this?

  • KhosrouKhosrou Member ✭✭✭

    @LarsNymand by the way I tried this , unfortunately no result ;(

    private void SetVoorzieningen()
            {
                var voorzieningen = _kamverViewModel.GetVoorzieningen(Kamer);
    
                for (int i = 0; i < voorzieningen.Count; i++)
                {
                    if (i < 4)
                    {
                        var image = new Image();
                        image.Source = voorzieningen.ElementAt(i).ImageSource;
                        VoorzieningenGrid.Children.Add(image, i, 0);
    
    
                    }
                    else
                    {
                        var image = new Image();
                        image.Source = voorzieningen.ElementAt(i).ImageSource;
                        VoorzieningenGrid.Children.Add(image, i - 4, 1);
                    }
                }
            }
    
  • LarsNymandLarsNymand DKMember ✭✭
    edited July 2018

    ahh wait.

    I just realized that you have both GetVoorzieningen and GetVoorzieningIcon.

    Sorry. What does GetVoorzieningen return?

  • KhosrouKhosrou Member ✭✭✭

    @LarsNymand the viewModel which I mentioned before

  • LandLuLandLu Member, Xamarin Team Xamurai

    @Khosrou As what @LarsNymand said, you just post the code about GetVoorzieningIcon. This method returns an image source, but the method GetVoorzieningen you used above seems it returns a list. So try to post the code about GetVoorzieningen.

  • KhosrouKhosrou Member ✭✭✭

    @LandLu here is the code of GetVoorzieningen

    public List<ImageWithCaption> GetVoorzieningen(Room room)
            {
                var voorzieningen = new List<ImageWithCaption>();
    
    
                foreach (var voorziening in room.Facilities)
                {
                    if (voorziening.Status)
                    {
                        var v = new ImageWithCaption
                        {
                            ImageSource = GetVoorzieningIcon(voorziening.Type),
                            Caption = voorziening.Name,
    
    
                        };
    
                        voorzieningen.Add(v);
                    }
                }
    
                return voorzieningen;
            }
    
  • KhosrouKhosrou Member ✭✭✭

    @LandLu oh man thank u so much, I indeed was forgot to set the build action to EmbeddedResources, so now I see the icons. But I miss the caption text under the icon tho, am I missing something?

  • LandLuLandLu Member, Xamarin Team Xamurai

    @Khosrou You just post your image code here, you can try to post more details about "your text under the icon" maybe on another thread. Moreover if this is helpful for you, please accept this as an answer to help other community fix this kind of issue.

Sign In or Register to comment.