0

有一个DockPanel,当我练习此代码时,它会将停靠内容添加到正确的 Dock 但我无法让它显示文本(即执行 Step1 和 Step2 等,如下所示)。我做了很多研究,没有任何工作。在此先感谢您的帮助。

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);
    }
}
4

2 回答 2

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 代码分开,您可以更加灵活。显然,这只是一个在停靠面板中使用文本块进行数据绑定的示例,但希望这能让您更好地理解。

于 2013-02-22T22:12:59.413 回答
0

你能像这样进入 xaml 并在 DockPanel 中放置一个文本块:

<DockPanel>
  <TextBlock Text="- Perform the step number 1 ."/>
</DockPanel>
于 2013-02-22T21:21:18.403 回答