0

I have a table with different columns I am showing two in this code :

<DataGridTextColumn Header="Allocated" Binding="{Binding Allocated}" >
  <DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
      <Setter Property="Background">
        <Setter.Value>
          <MultiBinding Converter="{StaticResource converter}">
            <Binding Path="Current_Phase" />
            <Binding Path="Status" />
          </MultiBinding>
        </Setter.Value>
      </Setter>
    </Style>
  </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Op10}" Header="WIP OP10" >
  <DataGridTextColumn.ElementStyle>
    <Style TargetType="{x:Type TextBlock}">
      <Setter Property="Background">
        <Setter.Value>
          <MultiBinding Converter="{StaticResource converter}">
            <Binding Path="Current_Phase" />
            <Binding Path="Status" />
          </MultiBinding>
        </Setter.Value>
      </Setter>
    </Style>
  </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

The problem I have My IConverterClass is returning a background colour and is putting green for both, but my current phase is "op30"(my parameters value) but still is changing the colour of column op10. I am totally lost, pls helppppp.

My converter Class

 object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {


     string type = values[0].ToString();
         string status = values[1].ToString();             

         if (type == "op10"  && status == "10")
         {
             return Brushes.Green;

         }
         else if ( type == "op30" && status == "30")
         {
             return Brushes.Green;
         }

        else
         {
             return DependencyProperty.UnsetValue;
         }           

   }

Please Helppp, I dont know what to do.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
CPM
  • 855
  • 3
  • 12
  • 14

1 Answers1

0

I don't understand your problem:
Your converter returns green for "op10" and "op30" and you bind that converter to both columns and therefore it changes both columns to green. If you don't want to change the column op10, remove the binding to the converter.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • Hi Daniel, I havent removed the the binding to the converter because I want also the column op10 to be changed when currentPhase is op10. Basically I have two columns op10 and op30 and I want to Change colour to columns according to the valeu of current phase. Thats why I am binding both. I Dont know other way of doing. Have u got any other suggesion plsss?! – CPM May 18 '11 at 10:02
  • So, you want the column op10 to be green if the currentPhase is op10 and only then. Any you want the column Allocated to be green only if currentPhase is op30? – Daniel Hilgarth May 18 '11 at 10:17
  • Yes, Thats Right!!Do I need different I converter Classes for each columns?! – CPM May 18 '11 at 10:29
  • Either that or you add a third parameter to the converter which you pass a constant value. This constant value then decides which if statement should be used. – Daniel Hilgarth May 18 '11 at 10:36
  • How can I pass Constant?! Cause that would be easier, cause I will have same problem for 7 Columns and didnt want to create class for each column if there is something that I can done. – CPM May 18 '11 at 10:37
  • Have a look here: http://stackoverflow.com/questions/3340821/how-to-pass-constant-value-for-1-binding-in-multi-binding – Daniel Hilgarth May 18 '11 at 10:39
  • Daniel, So I ll have one IconvertClass for my binding colours and other IconverterClass for my FixedValue?!Is that Right? – CPM May 18 '11 at 10:47
  • No... One converter! But instead of accepting only two values (Current_Phase and Status) it will accept three. – Daniel Hilgarth May 18 '11 at 10:48
  • 1
    Thanks a ton Daniel, I am passing value doing source – CPM May 18 '11 at 11:27