Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply converter to static property in XAML

Tags:

c#

wpf

xaml

How to set a converter for a static property? The following example shows my problem – I would like to convert a TextBlock text to upper case.

<UserControl x:Class="CoRiMaCorporate.HomeScreen.Controls.Home.ConfigurationControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mainResources="clr-namespace:MainSharedResources;assembly=MainSharedResources"
             xmlns:converters="clr-namespace:CommonClientLibrary.Converters;assembly=CommonClientLibrary" />
<UserControl.Resource>
    <converters:StringToUpperCaseStringConverter x:Key="stringToUpperCaseStringConverter" />
</UserControl.Resource>
<Grid>
    …
    <TextBlock Text="{x:Static mainResources:Lang.Applications}" />
    …
</Grid>

I looking for something like this:

<TextBlock Text="{Binding Converter=stringToUpperCaseStringConverter, ConverterParameter={x:Static mainResources:Lang.Applications}}" />
like image 791
David Avatar asked Feb 10 '17 12:02

David


1 Answers

static property goes to binding Source, converter provided by StaticResource

<TextBlock Text="{Binding Converter={StaticResource stringToUpperCaseStringConverter}, 
                          Source={x:Static mainResources:Lang.Applications}}" />
like image 141
ASh Avatar answered Nov 11 '22 15:11

ASh