Jump to content
Software FX Community

ConditionalAttributes and binding its Active property to a VM


AKhristenko
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...