2013-02-22 20 views
0

有一個DockPanel,當我練習此代碼時,它將停靠內容添加到正確的Dock但我不能讓它顯示文本(即執行Step1和Step2等。如下所示)。我做了很多研究,沒有任何成果。在此先感謝您的幫助。如何在C#中編寫Dock對象內容#

public void ShowInstructionForm() 
{ 
    dragDropForm = new DockContent(); 
    dragDropForm.Name = "Hints"; 

    dragDropForm.TabText = "Hints2"; 
    dragDropForm.ShowHint = DockState.DockRight; 
    dragDropForm.BackColor = Color.White; 
    dragDropForm.Text = "- Perform the step number 1 ." 
     + Environment.NewLine + " - Perform the Step number 2";          

    try 
    { 
     dragDropForm.Show(this.oDock.MainDock); 
    } 
    catch (Exception e) 
    { 
     MessageBox.Show(this.oDock.MainDock, "error happened " + e.Message); 
    } 
} 
+0

DockPanels必須是動態的嗎? – 2013-02-22 21:23:24

+0

我不這麼認爲 – user1298925 2013-02-22 22:09:51

回答

0

你可以進入XAML和放置文本塊,在這樣的DockPanel中:

<DockPanel> 
    <TextBlock Text="- Perform the step number 1 ."/> 
</DockPanel> 
1

個人而言,我會使用數據綁定來實現它是什麼,你想要讓你都秉承一個更僵硬的設計模式。

XAML

<Window x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525" 
    DataContext="{Binding RelativeSource={RelativeSource Self}}"> 
    <DockPanel> 
     <TextBlock Text="{Binding Path=Foo}" /> 
    </DockPanel> 
</Window> 

C#

public partial class MainWindow : Window 
{ 
    public string Foo { get; set; } 

    public MainWindow() 
    { 
     Foo = "hello world"; // Changing Foo 'automagically' changes your textblock value 
     InitializeComponent(); 
    } 
} 

這可以讓你可以通過讓業務邏輯從UI代碼分離更加靈活。顯然,這只是一個數據綁定的例子,它與一個停靠面板內的文本塊綁定,但希望這可以讓您更好地理解。

相關問題