locked
CustomControl ConverterParameter RRS feed

  • Question

  • Hello,

    I would like create a custom control and i need to convert value for displaying.

    The convert of this value depends of an other property of my control and i would like to take my control in ConverterParametrer

    I hope you understand what i wrote because. Thanks for your help

    Exemple :

    <ResourceDictionary

    xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

    xmlns:local="Local"

    >

    <local:ConvertWithNormalisation x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:CustomControl1}, ResourceId=ConvertWithNormalisation}"/>

    <Style TargetType="{x:Type local:CustomControl1}">

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type local:CustomControl1}">

    <TextBox x:Name="TxtNom" Text="{Binding Path=NomPersonne,

    Converter={StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:CustomControl1}, ResourceId=ConvertWithNormalisation}},  ConverterParameter= ???????,

    RelativeSource=/TemplatedParent}" />

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Style>

    </ResourceDictionary>

    Wednesday, January 25, 2006 4:27 PM

Answers

  • in my original example, can you take that Binding object and look at its Source value?  perhaps that will get filled in with your control since you told it RelativeSource.
    Friday, February 3, 2006 8:24 PM

All replies

  • I do not believe you can reference a resource in the enclosing scope from within the template.  You could try however embedding the resource directly in the template as in:

    <TextBox x:Name="TxtNom">

    <TextBox.Text>

    <Binding Path="NomPersonne">

    <Binding.Coverter>

    <local:ConverterWithNormalization .../>

    </Binding.Converter>

    <Binding.ConverterParameter>

    ???

    ...

    I am not sure what you are trying to achieve.  You do not need to pass the converter as a paramter to itself.

    Wednesday, January 25, 2006 5:59 PM
  • thanks to help me.

    my problème is :

    I have tow properties in my custom control :

    LastName of type string and doUpperName of type boolean.

    if the property doUpperName is true, I must upper the lastname to display for the user else I just display the lastname.

    When i arrive in the method  convert of my class ConverterWithNormalization i need to know the value of DoUpperName and in the future maybe an other value so i would like access to the control in my class ConverterWithNormalization.

    Is it possible

     

     

     

    Wednesday, January 25, 2006 6:17 PM
  • assuming that your control is what's being Templated here, you could try:

    <Binding.ConverterParameter>

        <Binding RelativeSource="/TemplatedParent"/>

    </Binding.ConverterParameter>

     

    or, if you wanted to use the other syntax:

    ...Text={Binding Path=NomPersonne,Converter={StaticResource...},ConverterParameter={Binding RelativeSource=/TemplatedParent}}...

    Thursday, January 26, 2006 12:41 AM
  • Thanks, but i'm sorry it's not good.

    When i look the argument parameter in my method  Convert, it's not my customcontrol, the type is System.Windows.Data.Binding.

    When i look into I don't find a reference of my control.

    Have you got an idea ?

     

     

    Thursday, January 26, 2006 8:48 AM
  • i try some differents Binding but it doesn't work.

    It's very stange that we can't have a reference on the control.

     

    Waiting a solution, i have define a static property to know what transformation i must apply but it's not thie ideal solution because this property provide the same value for all implementation  in my application.

    if somebody can help me ?

     

    Friday, February 3, 2006 9:21 AM
  • in my original example, can you take that Binding object and look at its Source value?  perhaps that will get filled in with your control since you told it RelativeSource.
    Friday, February 3, 2006 8:24 PM