beltrams Posted October 10, 2012 Report Share Posted October 10, 2012 Dear Forum, I have the followong settings for a Gantt chart: Anchor="Center" HorizontalAlignment="Center" VerticalAlignment="Center" As result I have the attached screenshot. As you can see, labels for small Gantt bars are cutted, they should be 8, 16 and 46 but you cannot read it. I have tried setting the offset but I doesnt work, does it work with Gantt? Anything I can do? Quote Link to comment Share on other sites More sharing options...
JuanC Posted October 10, 2012 Report Share Posted October 10, 2012 Unfortunately, if the labels are centered inside the bars, labels for small bars will be cutoff, a possibility would be to change the labels Anchor to Value and the HorizontalAlignment to Right. This will draw the labels to the right of each bars. We will consider adding a property to change the Anchor/HorizontalAlignment automatically when the labels do not fit. JuanC Quote Link to comment Share on other sites More sharing options...
beltrams Posted October 14, 2012 Author Report Share Posted October 14, 2012 Hi JuanC, I have found an hack that, at least for me, works: I attach the following attached property to the textbox I use as template for the PointLabeAttribute: public static class DataLabelPositionFixForGantt { /// <summary> /// Gets the attached dependency property used to apply the overridden position /// </summary> public static readonly DependencyProperty ChartTypeProperty = DependencyProperty.RegisterAttached( "ChartType", typeof(string), typeof(DataLabelPositionFixForGantt), new UIPropertyMetadata(string.Empty, OnChartTypePropertyChanged) ); /// <summary> /// Gets the attached dependency property value used to apply overridden position /// </summary> public static string GetChartType(DependencyObject obj) { Contract.Requires(obj != null); var obj_tmp = obj.GetValue(ChartTypeProperty); if (obj_tmp == null) throw new InvalidOperationException("Dependency object value must not be null"); return (string)obj_tmp; } /// <summary> /// Sets the attached dependency property value used to apply red condition /// </summary> public static void SetChartType(DependencyObject obj, string value) { Contract.Requires(obj != null); obj.SetValue(ChartTypeProperty, value); } static void OnChartTypePropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs args) { if (dpo == null) return; TextBlock el = dpo as TextBlock; if (el == null) throw new InvalidCastException("Object of type \"TextBlock\" expected"); if (args.NewValue is string == false) return; if ((string)args.NewValue == WidgetTypes.Gantt.Code) { var cont = el.FindVisualParent<ContentPresenter>(); if (cont == null) throw new InvalidCastException("Object of type \"ContentPresenter\" expected"); var pn = new PropertyChangeNotifier(cont, Canvas.LeftProperty); pn.ValueChanged += OnCanvasLeftChanged; cont.Loaded += OnLoaded; } else { var cont = el.FindVisualParent<ContentPresenter>(); if (cont == null) throw new InvalidCastException("Object of type \"ContentPresenter\" expected"); var pn = new PropertyChangeNotifier(cont, Canvas.LeftProperty); pn.ValueChanged -= OnCanvasLeftChanged; cont.Loaded -= OnLoaded; } } static void OnCanvasLeftChanged(object sender, EventArgs e) { PropertyChangeNotifier notifier = sender as PropertyChangeNotifier; if (notifier == null) throw new InvalidCastException("Object of type \"PropertyChangeNotifier\" expected"); UIElement el = notifier.PropertySource as UIElement; if (el == null) throw new InvalidCastException("Object of type \"UIElement\" expected"); if (Canvas.GetLeft(el) < 9) Canvas.SetLeft(el, 9); } static void OnLoaded(object sender, EventArgs e) { UIElement el = sender as UIElement; if (el == null) throw new InvalidCastException("Object of type \"UIElement\" expected"); if (Canvas.GetLeft(el) < 9) Canvas.SetLeft(el, 9); } }} I hope this will help others in the future. Cheers! 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.