korthmat Posted September 12, 2008 Report Share Posted September 12, 2008 Right now, I'm working on a graph that depicts sales as a percentage of expected sales. One of the requirements is that I have to draw a line across the graph at 100% of expected sales. A CustomGridLine would seem to be the solution. The problems start when I try to customize the CustomGridLine. In particular, the user should be able to specify: the color of the line; the text the line is labeled with; the color of the text (which should match the color of the line); and the alignment of the text (i.e., whether it appears on the left, on the right, or in the middle of the graph). So far, the only one of those three that I've been able to get is changing the text itself. This is the code I'm using right now: <cfx:CustomGridLine Value="1" Stroke="{Binding Source={StaticResource propertyBag}, Path=HundredPercentLineColor}" StrokeThickness="2"> <cfx:CustomGridLine.Title> <cfx:Title Content="{Binding Source={StaticResource propertyBag}, Path=HundredPercentLineText}" Foreground="{Binding Source={StaticResource propertyBag}, Path=HundredPercentLineColor}" TextAlignment="{Binding Source={StaticResource propertyBag}, Path=HundredPercentLineTextAlignment}" /> </cfx:CustomGridLine.Title> </cfx:CustomGridLine>This causes VS2008 to complain that Stroke isn't a DP, and even if I take that out so I can work on something else, I still can't change the text from the left side to the right side of the chart. Quote Link to comment Share on other sites More sharing options...
JuanC Posted September 12, 2008 Report Share Posted September 12, 2008 You can actually customize the gridline as you need but there are some issues that will prevent you from doing bindings to it, note that the following XAML will customize all the attributes you need <cfx:CustomGridLine Value="50" Stroke="Black" StrokeThickness="2"> <cfx:CustomGridLine.Title> <cfx:Title Foreground="Red" HorizontalAlignment="Right">Expected Sales</cfx:Title> </cfx:CustomGridLine.Title></cfx:CustomGridLine>We will work on allowing these bindings to work on future builds. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
korthmat Posted September 12, 2008 Author Report Share Posted September 12, 2008 Thanks! Unfortunately, I do actually need to be able to bind to those attributes, but at least I know it wasn't something stupid that I was doing. Now, to warn my colleagues... Quote Link to comment Share on other sites More sharing options...
korthmat Posted September 12, 2008 Author Report Share Posted September 12, 2008 I don't normally reply to myself, but editing timed out. I'd expect this to produce red text in the title: <cfx:CustomGridLine Value="50" Stroke="Black" StrokeThickness="2"> <cfx:CustomGridLine.Title> <cfx:Title Foreground="Red" HorizontalAlignment="Right">Expected Sales</cfx:Title> </cfx:CustomGridLine.Title> </cfx:CustomGridLine> Unfortunately, it doesn't seem to do so. Quote Link to comment Share on other sites More sharing options...
korthmat Posted February 10, 2009 Author Report Share Posted February 10, 2009 Just following up on this one-- For the most part, this seems to work with RC1. Right now, in a demo app, I've got this for my CustomGridLine declaration: <cfx:CustomGridLine Value="100" StrokeThickness="2" Stroke="{Binding Source={StaticResource customGridLineSettings}, Path=LineBrush}"> <cfx:CustomGridLine.Title> <cfx:Title Content="{Binding Source={StaticResource customGridLineSettings}, Path=Text}" Foreground="{Binding Source={StaticResource customGridLineSettings}, Path=LineBrush}" HorizontalAlignment="Left" /> </cfx:CustomGridLine.Title> </cfx:CustomGridLine> This allows me to change the stroke color, title content, and title color. However, I also need to be able to bind against HorizontalAlignment--and as soon as I change HorizontalAlignment="Left" to HorizontalAlignment="{Binding Source={StaticResource customGridLineSettings}, Path=HorizontalAlignment}", I get an InvalidCastException ("Specified cast is not valid.") Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 11, 2009 Report Share Posted February 11, 2009 We have fixed this issue. We can provide a hotfix (send email to wpf at softwarefx dot com) if you need to test this functionality. Regards, JuanC 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.