1

I am trying to multibind a formatted double value to a text box. I have a converter which takes in a double and a Formatter object and returns a formatted string to be displayed. The double is bound to a particular data source and the formatter is a property in the view model. The problem I'm having is that I'm unable to bind to the view model property. This is my code in xaml

    <StackPanel Grid.Row="0" Grid.Column="1">
      <TextBlock HorizontalAlignment="Left" Style="{StaticResource HintDataItemsStyle}">
        <TextBlock.Text>
         <MultiBinding Converter="{StaticResource FormatConverter}">
           <Binding Path="OpenValue" />
           <Binding Path="XLabelFormatterY1" />
         </MultiBinding>
        </TextBlock.Text>
      </TextBlock> 

This is the property in the view model

    private ILabelFormatter _labelFormatterY1;
    public ILabelFormatter XLabelFormatterY1
    {
        get { return _labelFormatterY1; }
        set
        {
            _labelFormatterY1 = value;
            OnPropertyChanged("XLabelFormatterY1");
        }
    }

So, in my converter I'm able to pick up the value for "OpenValue" ,but the runtime is unable to find XLabelFormatterY1. Most of the examples I have seen for multibinding bind to gui components. I'm trying to bind to the view model and would appreciate all help.

gatordude
  • 69
  • 3
  • 8
  • 1
    Is the DataContext set to the ViewModel object?. Did you check the Output window in VS for the binding error? – Tony Vitabile Apr 02 '14 at 20:28
  • Yes, the Data context is set to the view model object. It is able to bind to other properties in the view model, except the one inside the Multibinding. Is there a way to specify the datacontext inside the binding tag ? – gatordude Apr 02 '14 at 20:36
  • The bindings all work the same way. There's got to be something wrong with the spelling of the property name in either the binding or the parameter to OnPropertyChanged. Make sure those two agree and there are no extraneous non-printing characters in either. Also, make sure that those two strings match the name of the property. – Tony Vitabile Apr 02 '14 at 20:53

1 Answers1

4

Old question but without answer. I beleive that you are looking for this solution. If this answer doesn't work for you, try to explicitly set NotifyOnSourceUpdated="True" in the binding. And also double check if you have set correct AncestorType as wookietomwookie says in his answer.

Community
  • 1
  • 1
Artholl
  • 1,291
  • 1
  • 19
  • 38