locked
Dynamic ConverterParameter RRS feed

  • Question

  • Hello together, 

    Problem: I don't have the opportunity to change a static ConvertParameter in Xaml Code with diffrent values depending on business logic. 

    My Datagrid should have a numeric col to display every row a decimal value with a fraction part which should vary from row to row

    <data:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
         <TextBox x:Name="MengeKonv" Text="{Binding Converter={StaticResource   fractionConverter},ConverterParameter={StaticResource currentfraction}, Path=AV_Menge, Mode=TwoWay}" TextAlignment="Right" />
    </DataTemplate>
    </data:DataGridTemplateColumn.CellTemplate>

    To solve the item I have defined two local resources in my Xaml Code:

    <UserControl.Resources>
            <loc:FractionConverterLocal x:Key="fractionConverter"/>  <!-- Class derived from Interface IValueConverter-->
            <loc:CurrentFraction x:Key="currentfraction"/>  <!-- class to manipulate a paramter.. -->
       </UserControl.Resources>

    The FractionConvertLocal is a simple Class derived from IValueConverter with Convert an ConvertBack members.
    The second resource should be a Class to manipulate the numbers of fraction of my decimal member a Datagrid

    A Row Eventhandler in my DataGrid should change the value to currentfraction so that the fraction part of the decimal value can vary

    <data:DataGrid SelectionChanged="VerteilerschluesselDataGrid_SelectionChanged" >
    ...
    </data:DataGrid>
    void VerteilerschluesselDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      // Resources["currentNko"] = string.Format(Culterlnfo, formatString, value);  // Don't funtion...
    }
    public class CurrentNko
    {
    public string Value { get; set; }
    public CurrentNko(){}
    }

    I don't found a way to manipulate currentfraction of my ConverterParameter={StaticResource currentfraction}. Is it possible to declare and to manipulate Binding converter with its ConverterParameter in a Code Behind file?

    Have someone an idea to solve this problem?

    Thank you all - Greetings from Germany!!!

    Thursday, October 29, 2009 7:21 AM

Answers

  • Hi JSchatral,

    As I understand, you want to change currentfraction resource in code at runtime, in the meantime, all binding which applied converter should recalculate and update value.

    StaticResource binding doesn't have change notify mechanism like Binding, when you change the resource value, binding doesn't know it and won't refresh value.

    One workaround I would think is take advantage of Binding to "AV_Menge", when currentfraction changed, trigger the AV_Menge 's propertychanged event, then binding would got notify and update value. However, this is not an clean solution.

    Tuesday, November 3, 2009 1:00 AM

All replies

  • Unfortunately you can't bind to the ConverterParameter.

    Thursday, October 29, 2009 7:31 AM
  • Hi JSchatral,

    As I understand, you want to change currentfraction resource in code at runtime, in the meantime, all binding which applied converter should recalculate and update value.

    StaticResource binding doesn't have change notify mechanism like Binding, when you change the resource value, binding doesn't know it and won't refresh value.

    One workaround I would think is take advantage of Binding to "AV_Menge", when currentfraction changed, trigger the AV_Menge 's propertychanged event, then binding would got notify and update value. However, this is not an clean solution.

    Tuesday, November 3, 2009 1:00 AM