I am working on WPF with text. Now I want to edit text using FontDialog but I cannot set current style of text to FontDialog so the style of text change everytime I call FontDialog. Can you guys help me?
This my code:
System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog();
if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textAnnotation.Font.Size = fontDialog.Font.Size;
this.textAnnotation.Font.Name = fontDialog.Font.Name;
this.textAnnotation.Font.Underline = fontDialog.Font.Underline;
this.textAnnotation.Font.Strikeout = fontDialog.Font.Strikeout;
this.textAnnotation.Font.Bold = fontDialog.Font.Bold;
this.textAnnotation.Font.Italic = fontDialog.Font.Italic;
}
The Font object in WPF is different than the Font object in Windows Forms which your FontDialog returns.
You would be better off using something that is native to Wpf since the Font objects are different. There is a Sample Font Chooser on the Wpf Text blog. I would recommend looking into it.
something like this: