WinRT C# - create Converter string to string for binding Gridview

后端 未结 2 1324
旧巷少年郎
旧巷少年郎 2021-01-15 05:29

I come to you today for a \"little\" problem. I don\'t know how to create a simple converter because its the first time and I don\'t find a easy example. I would like to cre

2条回答
  •  盖世英雄少女心
    2021-01-15 06:24

    You want your class to inherit from the IValueConverter interface.

    public class ThumbToFullPathConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {           
            if (value == null)            
                return value;
    
            return String.Format("ms-appdata:///local/{0}", value.ToString());
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
    

    You then need to include this converter in your XAML (either as a resource local to the page, or an app resource available throughout the app). Import the namespace where on the page(s) you want to access the converter. (Change MyConverters to your namespace)

    xmlns:local="clr-namespace:MyConverters"
    

    Then set it as a resource

    
       
    
    

    Then you can use it where you like

    
    

提交回复
热议问题