Hello everyone,
My question may be a repeat of other conversion question but I feel mine is different.
Here goes... [simplified example].
public class DataWrapper<T>
{
public T DataValue{ get; set; }
public DataWrapper(T value)
{
DataValue = value;
}
public static explicit operator DataWrapper<T> (T value)
{
return new DataWrapper<T>(value);
}
public static implicit operator T(DataWrapper<T> data)
{
return data.DataValue;
}
}
Now, in my ViewModel:
public class ViewModel
{
public DataWrapper<string> FirstName { get;set; }
public DataWrapper<string> LastName { get; set; }
}
And in XAML:
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
My question is, will this work? Will WPF binding call the Implicit
and Explicit
converter in my DataWrapper<T>
class instead of needing to implement a IValueConverter
for each TextBlock
.