本篇文章簡單介紹UWP MVVM 如何在view中使用view以外的資源(以加入Converter 為例) 假設view上有個 Image 元件, 它的Visibility屬性被綁定在MyViewModel.IsHide 這個Property上, <Image Margin= "200,200,0,0" MaxWidth= "50" MaxHeight= "50" HorizontalAlignment= "Center" VerticalAlignment= "Center" Source= "ms-appx:///Assets/googleIcon.png" Visibility= "{Binding IsHide, Mode=OneWay}" /> 為了提升可讀性, 我們將 MyViewModel.IsHide 宣告成布林型別, 但由於 Visibility 屬性只能接受整數型別, 所以我們需要多做一個Converter 來轉換成UI上需要的值 public class BoolToIntConvert : IValueConverter { public object Convert ( object value , Type targetType, object parameter, string language) { return ( bool ) value == true ? Visibility.Collapsed : Visibility.Visible; } public object ConvertBack ( object value , Type targetType, object parameter, string language) { t...