Binding to WPFFont.Family, target not updating correctly
Posted: 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
MainWindow.xaml.cs
SampleContext.cs:
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>
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);
}
}
}
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
)
);
}
}
}