مشاركة عبر


كيفية القيام بما يلي: الحصول على أو تعيين قيمة مرساه

يوضح المثال التالي كيفية تعيين القيمة Dock لكائن. يستخدم المثال الأساليب GetDock و SetDock الخاصة بـ DockPanel.

مثال

يقوم المثال بإنشاء مثيل من العنصر TextBlock، txt1 ، ويقوم بتعيين قيمة Dock الخاصة بـ Top باستخدام الأسلوب SetDock الخاص بـ DockPanel. ثم يقوم بإضافة قيمة الخاصية Dock إلى Text الخاص بالعنصر TextBlockباستخدام الأسلوب GetDock . وأخيراً، يضيف المثال العنصر TextBlock الى الأصل DockPanel ، dp1.

' Create the Panel DockPanel
dp1 = New DockPanel()

' Create a Text Control and then set its Dock property
txt1 = New TextBlock()
DockPanel.SetDock(txt1, Dock.Top)
txt1.Text = "The Dock Property is set to " & DockPanel.GetDock(txt1).ToString()
dp1.Children.Add(txt1)
_mainWindow.Content = dp1
_mainWindow.Show()
            // Create the Panel DockPanel
            dp1 = new DockPanel();

            // Create a Text Control and then set its Dock property
            txt1 = new TextBlock();
            DockPanel.SetDock(txt1, System.Windows.Controls.Dock.Top);
            txt1.Text = "The Dock Property is set to " + DockPanel.GetDock(txt1);
            dp1.Children.Add(txt1);
            mainWindow.Content = dp1;
            mainWindow.Show();

راجع أيضًا:

المرجع

DockPanel

GetDock

SetDock

المبادئ

نظرة عامة على اللوحات