This article is currently in the process of being translated into Arabic (~24% done).

تطبيق WPF:


عندما تقوم بانشاء تطبيق WPF فان اول شيء تلقاه هو كلاس النافذه. وهو يعمل بمثابة اصل واساس النافذه ويزودك بالحدود , شريط العنوان , وازرار التكبير , التصغير والإغلاق . النافذة في WPF هي عبارة عن مزيج من ملفات XAML الـ بامتداد (.xaml) حيث ان عنصر النافذة >Window< هو الاساس , وكذلك ملف الكود الخلفي بامتداد .cs اذا كنت تستخدم الفيجول ستوديو المجاني Visual Studio (Express) وقمت بانشاء تطبيق WPF فانة سينشىء النافذة الافتراضيه لك , والتي ستبدو كالتالي :

<Window x:Class="WpfApplication1.Window1"
    Title="Window1" Height="300" Width="300">


السمة x:class تخبر ملف XAML أي فئة يستخدمها ، في هذه الحالة Window1 ، الذي أنشأه Visual Studio لنا أيضًا. سوف تجده في شجرة المشروع في VS ، كعقدة فرعية لملف XAML. بشكل افتراضي ، يبدو الأمر كالتالي:

using System;
using System.Windows;
using System.Windows.Controls;
//…more using statements

namespace WpfApplication1
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        public Window1()

As you can see, the Window1 class is definied as partial, because it's being combined with your XAML file in runtime to give you the full window. This is actually what the call to InitializeComponent() does, which is why it's required to get a full functioning window up and running.

اذا عدنا الى ملف الXAML , سوف تلاحظ العديد من المميزات مثيرة الاهتمام فى عنصر النافذه , مثل العنوان , الذى يحدد عنوان النافذه ( يظهر فى شريط العنوان) وكذلك بداية العرض والطول. هنالك ايضا العديد من تعريفات الnamespace , التى سنتحدث عنها فى فصل الXAML.

You will also notice that Visual Studio has created a Grid control for us inside the Window. The Grid is one of the WPF panels, and while it could be any panel or control, the Window can only have ONE child control, so a Panel, which in turn can contain multiple child controls, is usually a good choice. Later in this tutorial, we will have a much closer look into the different types of panels that you can use, as they are very important in WPF.

Important Window properties

The WPF Window class has a bunch of interesting attributes that you may set to control the look and behavior of your application window. Here's a short list of the most interesting ones:

Icon - Allows you to define the icon of the window, which is usually shown in the upper left corner, to the left of the window title.

ResizeMode - This controls whether and how the end-user can resize your window. The default is CanResize, which allows the user to resize the window like any other window, either by using the maximize/minimize buttons or by dragging one of the edges. CanMinimize will allow the user to minimize the window, but not to maximize it or drag it bigger or smaller. NoResize is the strictest one, where the maximize and minimize buttons are removed and the window can't be dragged bigger or smaller.

ShowInTaskbar - The default is true, but if you set it to false, your window won't be represented in the Windows taskbar. Useful for non-primary windows or for applications that should minimize to the tray.

SizeToContent - Decide if the Window should resize itself to automatically fit its content. The default is Manual, which means that the window doesn't automatically resize. Other options are Width, Height and WidthAndHeight, and each of them will automatically adjust the window size horizontally, vertically or both.

Topmost - The default is false, but if set to true, your Window will stay on top of other windows unless minimized. Only useful for special situations.

WindowStartupLocation - Controls the initial position of your window. The default is Manual, which means that the window will be initially positioned according to the Top and Left properties of your window. Other options are CenterOwner, which will position the window in the center of it's owner window, and CenterScreen, which will position the window in the center of the screen.

WindowState - Controls the initial window state. It can be either Normal, Maximized or Minimized. The default is Normal, which is what you should use unless you want your window to start either maximized or minimized.

There are lots of other attributes though, so have a look for yourself and then move on to the next chapter.

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!