This project is read-only.

Does CaseConverter work with a TextBox?

Oct 20, 2011 at 2:59 PM

Hi, I have just tried the following XAML:

<TextBox Name="txtTest" Text="{Binding MyProperty, Converter={con:CaseConverter Upper}}"/>

<Label Content="{Binding Text, ElementName=txtTest, Converter={con:CaseConverter Upper}}"/> 

<Label Content="{Binding Text, ElementName=txtTest, Converter={con:CaseConverter Lower}}"/>

Both labels correctly convert the text to the appropriate case, but the TextBox itself doesn't seem to be affected.  Am I doing something wrong?

Thanks,

Brian



Oct 20, 2011 at 3:08 PM

Hi, I just noticed that TextBox has a CharacterCasing property, which does what I want, so I'm using that instead.  However, I would still like to know why the converter doesn't work. :/

Brian


Oct 21, 2011 at 2:09 PM

What versions of WPF and WPF Converters are you using? I just tried this on WPF 4 with the latest WPF Converters and it worked fine.

Kent

Oct 24, 2011 at 9:00 AM

I am using WPF 4 and just downloaded the WPF Converters via Nuget, so I expect they are the latest too (Version property says 1.1.0.0. and Runtime Version says v4.0.30319.  I just created a new WPF Application project and modified the MainWindow XAML as follows:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:con="clr-namespace:Kent.Boogaart.Converters.Markup;assembly=Kent.Boogaart.Converters"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>
            <TextBox Name="txtTest" Text="{Binding MyProperty, Converter={con:CaseConverter Upper}}"/>
            <Label Content="{Binding Text, ElementName=txtTest, Converter={con:CaseConverter Upper}}"/>
            <Label Content="{Binding Text, ElementName=txtTest, Converter={con:CaseConverter Lower}}"/>
        </StackPanel>
    </Grid>
</Window>

I modified the code behind as follows:
 
    public partial class MainWindow : Window
    {
        public String MyProperty { get; set; }
        public MainWindow()
        {
            InitializeComponent();

            DataContext = this;
        }
    }
 
The result is that the text box allows mixed case text to be typed (and does not change it to upper case), but the labels
force upper and lower case respectively (as expected). :(
 
Brian