Binding to WPFFont.Family, target not updating correctly

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
TRVRSE
Posts: 21
Joined: Fri May 30, 2014 1:27 pm

Binding to WPFFont.Family, target not updating correctly

Post by TRVRSE » Fri Jun 06, 2014 1:47 pm

In my project, I have a Windows.Media.FontFamily property that I wish to bind to the WPFFont object's Family property. I would like a change in source property to be reflected in the chart. But, this is currently not happening. The Source property is being changed. And it looks like the target property is being changed. But it does not redraw the Title. I can force a redraw of the Title by mousing over, in which case, the new FontFamily is visible.

Is this a bug? Any Workaround or solutions?

Here's my sample code. I apologize if it looks familiar, as I'm using the same sample project that I used when posting about another problem.


MainWindow.xaml

Code: Select all

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lcu="http://www.arction.com/schemas/" x:Class="BindingSample.MainWindow"
				xmlns:local="clr-namespace:BindingSample"
        Title="MainWindow" Height="350" Width="525">
	<Window.DataContext>
		<local:SampleContext/>
	</Window.DataContext>

	<Grid>
		<lcu:LightningChartUltimate x:Name="chart"
			HorizontalAlignment="Stretch"
			VerticalAlignment="Stretch" >
			<lcu:LightningChartUltimate.Title>
				<lcu:ChartTitle Font="Times new roman, 42"/>
			</lcu:LightningChartUltimate.Title>

			<lcu:LightningChartUltimate.ViewXY>
				<lcu:ViewXY>
					<lcu:ViewXY.GraphBackground>
						<lcu:Fill Color="Gray"/>
					</lcu:ViewXY.GraphBackground>
					<lcu:ViewXY.AxisLayout>
						<lcu:AxisLayout AutoAdjustMargins="False"/>
					</lcu:ViewXY.AxisLayout>

					<lcu:ViewXY.YAxes>
						<lcu:AxisY/>
					</lcu:ViewXY.YAxes>
					<lcu:ViewXY.XAxes>
						<lcu:AxisX/>
					</lcu:ViewXY.XAxes>
				</lcu:ViewXY>
			</lcu:LightningChartUltimate.ViewXY>
		</lcu:LightningChartUltimate>
	</Grid>
</Window>
MainWindow.xaml.cs

Code: Select all

using Arction.WPF.LightningChartUltimate;
using Arction.WPF.LightningChartUltimate.Views.ViewXY;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BindingSample
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();

			// Bind the data contexts SampleMargin property to the Margins property of the ViewXY.
			Binding FontBinding = new Binding("Family");
			FontBinding.Mode = BindingMode.TwoWay;
			FontBinding.BindsDirectlyToSource = true; ;
			FontBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
			FontBinding.Source = DataContext;
			BindingOperations.SetBinding(chart.Title.Font, WPFFont.FamilyProperty, FontBinding);
		}
	}
}
SampleContext.cs:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;

namespace BindingSample
{
	public class SampleContext : DependencyObject
	{
		int i = 0;
		private DispatcherTimer dispatcherTimer;

		public SampleContext()
		{
			dispatcherTimer = new DispatcherTimer();
			dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 2);
			dispatcherTimer.Tick += new EventHandler(OnDispatcherTimerTick);
			dispatcherTimer.Start();
		}

		private void OnDispatcherTimerTick(object sender, EventArgs e)
		{
			i++;

			if (i >= 3)
			{
				i = 0;
			}

			if (i == 2)
			{
				Family = new FontFamily("Times New Roman");
			}
			else if (i == 1)
			{
				Family = new FontFamily("Courier");
			}
			else
			{
				Family = new FontFamily("Arial");
			}

		}

		public FontFamily Family
		{
			get
			{
				return (FontFamily)GetValue(FamilyProperty);
			}

			set
			{
				SetValue(FamilyProperty, (Object)value);
			}
		}

		public static readonly DependencyProperty FamilyProperty;



		static SampleContext()
		{
			FamilyProperty =
				DependencyProperty.Register(
					"Family",
					typeof(FontFamily),
					typeof(SampleContext),
					new PropertyMetadata(
						(Object)(new FontFamily("Arial")),
						null
					)
				);
		}
	}
}


ArctionJari

Re: Binding to WPFFont.Family, target not updating correctly

Post by ArctionJari » Mon Jun 09, 2014 10:39 am

Yes, it is a bug. :? Thanks for bringing this up. We'll try to fix it asap. As a temporary fix you could put Family property setting between LightningChartUltimate.BeginUpdate and EndUpdate methods but you have to provide DataContext object with a reference to your chart object to call those methods or use a timer in your Window class that runs a little bit faster than your current timer.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Binding to WPFFont.Family, target not updating correctly

Post by ArctionPasi » Mon Jun 09, 2014 5:03 pm

Fixed in v.6.0.5 today.
LightningChart Support Team, PT

TRVRSE
Posts: 21
Joined: Fri May 30, 2014 1:27 pm

Re: Binding to WPFFont.Family, target not updating correctly

Post by TRVRSE » Tue Jun 10, 2014 6:44 pm

Thanks for the fix!

Post Reply