Posted on Leave a comment

ViewModel Image binding based on Condition – XAML

If you want to show a specific image in a Xamarin.Forms app based on a condition, you can Image.Triggers

For example you have an Image element in your XAML and you want to show a different image based on a database query. In order to do that, you should place the pictures that you want to use in the appropriate folders.

  • For iOS the pictures must be located under Resources folder.
  • For Android the pictures should be in Resources/drawable
  • For UWP you must place the pictures in the root directory of the project.
 <Image WidthRequest="80"  Source="{Binding Category}" HeightRequest="80">
                                <Image.Triggers>
                                    <DataTrigger TargetType="Image" Binding="{Binding Category}" Value="ID Number">
                                        <Setter Property="Source" Value="id.png" />
                                    </DataTrigger>
                                    
                                     <DataTrigger TargetType="Image" Binding="{Binding Category}" Value="Tax Identification Number">              
                                        <Setter Property="Source" Value="tax.png" />
                                    </DataTrigger>

                                     <DataTrigger TargetType="Image" Binding="{Binding Category}" Value="Other">              
                                        <Setter Property="Source" Value="other.png" />
                                    </DataTrigger>
                                    
                                </Image.Triggers>
    </Image>

As a result your image will change upon the value of the Category element. If the Category value would be ID Number then the image should be id.png etc..

Posted on Leave a comment

Map Windows OS disks with VMware hard disks

It is a bit tricky to map Windows OS disks with VMware disks especially when two or more disks have the same size, because vmware does not provide the disk name, but only scsi identifiers. As a result if I had to extend a particular disk, I must find the right one.

From VMware hard disk Advanced Settings, you can find a SCSI code for a particular disk 1:2 that vmware names hard disk 2. Note that hard disk 2 could ne different from Hard disk 2 that the Windows OS would name. You could determine that from the capacity of the Disk if they were different, but it could be also different even when the capacity (GB) were the same.

 

So how could you do the mapping?

First of all you should run the following powershell command. It would give you scsi identifiers for all Windows OS disks.

get-wmiobject -class Win32_DiskDrive | select deviceID,size,scsiport,scsitargetid

 

Windows OS start numbering controllers from a random positive number and adds one for each subsequent controllers. As a result if the numbering starts from 3, then 3 scsiport would match to 0 scsiport in VMware (because numbering starts from 0). In the particular example if you would see 4:2 from the powershell command, it would be the disk that you can see in the picture above.

 

Posted on Leave a comment

Send signals between Mainpage.xaml.cs and Viewmodel – Xamarin.Forms

In a recent application I wanted to inform a Listview with a specific ItemTemplate to update its data source on back button with a synchronous data fetching mechanism(so this was not automatic).

So the goal was to send a “signal” to my Viewmodel when the page was loaded to perform an action. This can be done using MessageCenter with Xamarin.Forms.

The solution was to send an update signal every time OnAppearing() method of the MainPage.xaml was hit and inform the ViewModel to perfom an action.

 protected override void OnAppearing()
        {
            MessagingCenter.Send<nameofapp.App>((nameofapp.App)Xamarin.Forms.Application.Current, "update");
        }

Then perform action on MainPageViewModel

public MainPageViewModel()
        {
           
            MessagingCenter.Subscribe<nameofapp.App>((nameofapp.App)Application.Current, "update", (sender) => {
                var result = viewmodel.fetchData();
            });


        }