I have a custom ControlTemplate for my Groupbox:
<converters:StringCaseConverter x:Key="stringCaseConverter" />
<Style TargetType="GroupBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupBox">
<Border BorderBrush="#DEEBF3" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" Margin="2,2,2,2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Label Foreground="#3B3A35" FontSize="17" FontWeight="SemiBold" FontFamily="Segoe UI">
<ContentPresenter Margin="4,0,4,0" ContentSource="Header" RecognizesAccessKey="True">
<ContentPresenter.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Text" Value="{Binding Converter={StaticResource stringCaseConverter}, ConverterParameter='Title'}" />
</Style>
</ContentPresenter.Resources>
</ContentPresenter>
</Label>
</StackPanel>
<ContentPresenter Grid.Row="1" Margin="14" />
</Grid>
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1" Opacity=".5">
<GradientStop Offset="0" Color="#AFBCC7" />
<GradientStop Offset=".1" Color="#C3D6E4" />
<GradientStop Offset=".9" Color="#C6D8E2" />
<GradientStop Offset="1" Color="#B4C3CF" />
</LinearGradientBrush>
</Border.Background>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
As you can see, there is a converter that tries to convert the header text to TitleCase using the following Converter:
[ValueConversion(typeof(string), typeof(string))]
public class StringCaseConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
var currentString = (string)value;
var conversion = (string)parameter;
if (conversion == "Base64")
{
byte[] txtByte = Encoding.Default.GetBytes(currentString);
string outputString = System.Convert.ToBase64String(txtByte);
return outputString;
}
if (conversion == "Upper")
return currentString.ToUpper(culture);
if (conversion == "Lower")
return currentString.ToLower(culture);
if (conversion == "Title")
{
TextInfo text = culture.TextInfo;
return text.ToTitleCase(currentString);
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
The problem I am having here is that when I debug the code, the code executes perfectly and I step into the converter code, where it actually converts the header text into TitleCase. BUT... when I look at the app, the header is not reflecting what the converter returned.
Any idea why?