views:

113

answers:

2

Hi all, I have custom control with some text in content template:

<ControlTemplate TargetType="{x:Type local:TouchScreenKey}">    
    <TextBlock><ContentPresenter Content="{TemplateBinding Title, Converter={StaticResource CaseConverter}}" /></TextBlock>
</ControlTemplate>

and custom IValueConverter CaseConverter - with property UpperCase. So, when UpperCase property of converter set to true it converts text to upper case on binding. Everything goes fine if I change UpperCase in markup. But if i change property in runtime - nothing happens - because changing converter property not force my control to rebind. How can I rebind control which uses converter on converter's property change?

A: 

As far as I know there is no way to tell converter to update all targets. Converter knows nothing about targets. It's just a stateless function, F(x), takes one value and returns another.

To update property you should ask WPF to do so. For example, if property is bound to some source property, you can implement INotifyPropertyChanged, and trigger PropertyChanged event. Or you can ask BindingOperations to get binding expression, and invoke UpdateTarget() manually.

Maybe converter isn't the best choice here? You may also want to consider using Attached Properties to change capitalization.

Anvaka
Thanks for answer, i solved that with Multibinding and MultiValueConverter
alek.sys
You are welcome :). I'm glad you could find the answer yourself. Cheers
Anvaka
A: 

It may help someone - I found solution - using multibinding

<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
<ContentPresenter>
    <ContentPresenter.Content>
        <MultiBinding Converter="{StaticResource MultiCaseConverter}">
            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Title" />
            <Binding ElementName="TouchKeyboard" Path="UpperCase" />
        </MultiBinding>
    </ContentPresenter.Content>
</ContentPresenter>

and wrote MultiCaseConverter - which convert first parameter depending from second (UpperCase)

alek.sys