AKhristenko Posted May 4, 2012 Report Share Posted May 4, 2012 Dear Forum, I am trying to solve a task of showing negative values in red only when the chart is of type Bar or Gantt. There is no code-behind and same View and View model are used for all charts. Currently I am trying to make use of conditional attribute and its property Active to switch the colouring on/off when needed. I have a property in my view model like this: public bool ShowNegativesInRed { get { return (this.ChartConfig.WidgetType == ChartWidgetTypes.Gantt); } } Then in the View I am doing the following: ... When I start the app and try to display the chart, "Active" is always resolved to true and I get a binding error: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ShowNegativesInRed; DataItem=null; target element is 'RangeCondition' (HashCode=20263529); target property is 'Active' (type 'Boolean') Googling for this error I found someone advising to declare that thing causing the error in a local resource and use it from there, however I cannot think of how to move my cfx:RangeCondition to a local resource. If anyone has an idea how to do that or maybe an alternative solution for my initial task that would be highly appreciated. Quote Link to comment Share on other sites More sharing options...
AKhristenko Posted May 4, 2012 Author Report Share Posted May 4, 2012 Sorry, formatting got screwed up. Here it is again Dear Forum, I am trying to solve a task of showing negative values in red only when the chart is of type Bar or Gantt. There is no code-behind and same View and View model are used for all charts. Currently I am trying to make use of conditional attribute and its property Active to switch the colouring on/off when needed. I have a property in my view model like this: public bool ShowNegativesInRed { get { return (this.ChartConfig.WidgetType == ChartWidgetTypes.Gantt); } } Then in the View I am doing the following: <cfx:Chart Gallery="{Binding Path=WidgetType, Mode=OneWay}" ...> <cfx:Chart.ConditionalAttributes> <cfx:ConditionalAttributes Fill="Red" Stroke="Red"> <cfx:ConditionalAttributes.Condition> <cfx:RangeCondition To="0" Active="{Binding Path=ShowNegativesInRed}" /> </cfx:ConditionalAttributes.Condition> </cfx:ConditionalAttributes> </cfx:Chart.ConditionalAttributes> ... </cfx:Chart> When I start the app and try to display the chart, "Active" is always resolved to true and I get a binding error:System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ShowNegativesInRed; DataItem=null; target element is 'RangeCondition' (HashCode=20263529); target property is 'Active' (type 'Boolean')Googling for this error I found someone advising to declare that thing causing the error in a local resource and use it from there, however I cannot think of how to move my cfx:RangeCondition to a local resource. If anyone has an idea how to do that or maybe an alternative solution for my initial task that would be highly appreciated. Quote Link to comment Share on other sites More sharing options...
AKhristenko Posted May 15, 2012 Author Report Share Posted May 15, 2012 The problem is solved using DataContext spy approach as described at http://www.codeproject.com/Articles/27432/Artificial-Inheritance-Contexts-in-WPF Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.