DataTrigger Usage

后端 未结 2 1243
傲寒
傲寒 2021-01-25 01:55

Here is pseudo code for what I want to implement in xaml

IF vm.AvatarFilePath IS NOT NULL THEN
    Image.Source = {Binding AvatarPath}
ELSE
    If vm.Gender == {         


        
2条回答
  •  灰色年华
    2021-01-25 02:43

    As an option you can use custom converter class and convert viewmodel to bitmap source. If you wish to use triggers, then you can use some multidatatriggers and/or multiconverters for example for cases when you want to show Img_Male.

    But these solutions isn't really good I think, better to introduce property/logic and simply bind image source to it and handle these view logic inside viewmodel. Using this approach you can write unit tests for this logic also.

提交回复
热议问题