Reputation: 1034
I have the following problem.
I want to delimit a string be a certain symbol. This could be a comma, a space, a tab or something else.
I store that delimiter symbol in my dependency property Delimiter
.
In my WPF code I have the following radio button which should be checked if Delimiter
belongs to that radio button.
This is the WPF code:
<RadioButton IsChecked="{Binding ElementName=view, Path=Delimiter, Converter={StaticResource MyConverterToCheckForEquality}, ConverterParameter=\t}" Tag="\t" />
If I check out the parameter in my converter the value is 't'.
I wanted '\t' so I tried the following options:
(Note: I added extra spaces and backslashes to display it here correctly).
The result is very saddening... Triple and Double backslash gives me double backslash, Single gives me none. & #92; also gives me zero backslashes.
Maybe the most frustrating thing is that when I use the Tag property to set the delimiter \t just works fine and is not extra escaped in the process...
Can somebody explain why this happens, why none of these options worked and how to fix it?
UPDATE
When I use a multibinding within a multidatatrigger the result is diffrent:
<Binding ElementName="view" Path="Delimiter" Converter="{StaticResource MyConverterToCheckForEquality}" ConverterParameter="\\\t" />
The parameter value in my converter is now '\\\\\\t', however I still can't make it work.
I can replace the value but that would mean I have to use a different variable in my code behind file, which would be pretty ugly. I guess there is no other solution though.
Upvotes: 2
Views: 1897
Reputation: 10553
Try this:
ConverterParameter='	'
	
represents \t
(#9 is the ASCII equivalent of horizontal tab)
I tested it by passing it into my converter as the converter parameter, and it shows up correctly. Here's my test code:
XAML:
<Window.Resources>
<local:MyConverter x:Key="MyConverter" />
</Window.Resources>
<Grid Tag="NotUsed_Ignore">
<TextBox Text="{Binding Converter={StaticResource MyConverter}, ConverterParameter='	', RelativeSource={RelativeSource Mode=Self}}, Path=Parent.Tag" />
</Grid>
C# codebehind:
public sealed class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (parameter.Equals("\t")) return "Success!";
return "Failure!";
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
When I run this, the window shows a TextBox with the text "Success!"
Upvotes: 5
Reputation: 9265
Why not trying something like that :
public static class Delimiters {
// ...
public static char Tab { get { return '\t'; } }
// ...
}
Then
<Binding ... ConverterParameter="{x:Static Delimiters.Tab}" ... />
Upvotes: 0
Reputation: 132618
You might just have to .Replace("\\", "\")
the slashes....
MSDN says the following, but apparently it's incorrect
If the next character is a "\" (Unicode code point 005C), consume that "\" without adding it to the text value, then consume the following character and append that to the value.
Upvotes: 0