2012-03-18 111 views
-2

在的WinForms很容易如何更改WPF中的字體?

private void mfont_Click(object sender, System.EventArgs e) 
{ 
    fd.ShowColor = true; 
    fd.ShowDialog(); 
    txt.Font = fd.Font; 
    txt.ForeColor = fd.Color; 
} 

如何做相同的WPF?我打開字體對話框,但我不知道如何使這兩條線在WPF工作:

private void mfont_Click(object sender, System.EventArgs e) 
{ 
    txt.Font = fd.Font; 
    txt.ForeColor = fd.Color; 
} 
+0

看看對象IE的屬性點擊元素設置字體,在屬性中可以設置它。如果你想在代碼中做到這一點,設置元素的ID,並在代碼中設置它 – cpoDesign 2012-03-18 20:46:41

回答

1

您可以使用txt.FontFamilyFontWeightFontStyle等等

WPF是所有關於綁定,因此很多東西都不同於WinForms。主要是因爲Bindings,一些像Font這樣的東西被分成多個屬性,如p.e. FontFamily,FontWeight和FontStyle,這使得綁定更容易。

看看:
你的回答:TextBox in WPFFontFamily Property
Bindings(強烈勸提前讀取)
An introduction to WPF(也許這可以幫助你)

WPF可能看起來像的WinForms,但它絕對不同。然而在我看來,WPF的好處大大超過了WinForms的好處。祝你好運。