Scottintexas
Well-known member
I have never used a converter until I tried today and I didn't get it right.
The XAML resources are in a Resource Library which is referenced at the top of the View XAML
And finally the resource reference looks like this
The project wont build. The error is "The resource "StopBitConverter" has an incompatible type" at the binding line which would be line 4 in XAML the code above.
Also "The name "StopBitConverter" does not exist in the namespace "clr-namespace:Izod_Impact.ViewModels" which is not true. It is used by all of the views. But I think once the incompatible type issue is resolved, the other error will go away. Maybe not.
How do I do this right?
The Converter Class:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
StopBits sb = (StopBits)value;
string stops = string.Empty;
switch (sb)
{
case StopBits.None:
stops = "None";
break;
case StopBits.One:
stops = "One";
break;
case StopBits.OnePointFive:
stops = "OnePointFive";
break;
case StopBits.Two:
stops = "Two";
break;
}
return stops;
}
The XAML with the Binding:
<TextBlock Grid.Column="1"
Grid.Row="3"
Style="{StaticResource ComportPropertiesStyle}"
Text="{Binding Converter={StaticResource StopBitConverter}}">
</TextBlock>
The XAML resources are in a Resource Library which is referenced at the top of the View XAML
<ResourceDictionary Source="./ViewResources.xaml" />
And finally the resource reference looks like this
<vm:StopBitConverter x:Key="StopBitConverter"/>
Which is suspicious because it just looks wrong.The project wont build. The error is "The resource "StopBitConverter" has an incompatible type" at the binding line which would be line 4 in XAML the code above.
Also "The name "StopBitConverter" does not exist in the namespace "clr-namespace:Izod_Impact.ViewModels" which is not true. It is used by all of the views. But I think once the incompatible type issue is resolved, the other error will go away. Maybe not.
How do I do this right?