Winform中調用WPF控件


有兩種調用方式,在使用之前都將控件“ElementHost”添加到 Form 中:

方式一:

直接聲明wpf中控件(使用 Windows.Controls)

Public Class Form1
    Dim txt As Windows.Controls.TextBox = New Windows.Controls.TextBox() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load        
txt.SpellCheck.IsEnabled = True ElementHost1.Child = txt End Sub End Class

方式二:

首先新建一個 ”User Control“,

之后,如下編輯“UserControl1.xaml”中的內容:

<Grid>
    <TextBox x:Name="textBox" Foreground="Black" FontSize="24" Margin="0"></TextBox>
    <TextBox SpellCheck.IsEnabled="True" />
</Grid>

最后,修改”Form1.vb“代碼如下:

Public Class Form1 Private uc As UserControl1 = New UserControl1() Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ElementHost1.Child = uc End Sub
End Class

結果如下所示:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM