TOC

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

العناصر الأساسية:

The PasswordBox control

لكتابة النصوص في WPF لدينا أداة TextBox، لكن ماذا عن كتابة كلمات المرور؟ كلاهما يعملان بشكل مماثل جداً لكننا نريد من WPF ان يعرض شيئاً ما بدلاً من الحروف الأصلية عند كتابة كلمات المرور، لحمايتها من الناس الفضوليين. لهذا الغرض، WPF توفر أداة PasswordBox التي توازي في سهولتها أداة TextBox. دعني أوضح لك ذلك بمثال:

<Window x:Class="WpfTutorialSamples.Basic_controls.PasswordBoxSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="PasswordBoxSample" Height="160" Width="300">
    <StackPanel Margin="10">
        <Label>Text:</Label>
        <TextBox />
        <Label>Password:</Label>
        <PasswordBox />
    </StackPanel>
</Window>

في لقطة الشاشة الموضحة، قمت بإدخال نفس النص تماماً في كلا صندوقي النص، لكن في الصندوق الخاص بكلمة المرور، تم استبدال الحروف بالنقاط. بإمكانك في الواقع التحكم في الرمز الذي يظهر بدلاً من الحرف الحقيقي باستخدام الخاصية: PasswordChar

<PasswordBox PasswordChar="X" />

في هذه الحالة، الرمز X سيستخدم بدلاً من النقاط. في حالة احتجت الى التحكم بطول كلمة المرور، لديك خاصية: MaxLength

<PasswordBox MaxLength="6" />

لقد استخدمت كلتا الخاصيتين في هذا المثال المُحدّث:

<Window x:Class="WpfTutorialSamples.Basic_controls.PasswordBoxSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="PasswordBoxSample" Height="160" Width="300">
    <StackPanel Margin="10">
        <Label>Text:</Label>
        <TextBox />
        <Label>Password:</Label>
        <PasswordBox MaxLength="6" PasswordChar="X" />
    </StackPanel>
</Window>

لاحظ كيف أن الحروف الآن قد استبدلت بالرمز X، ولم يسمح لي سوى إدخال 6 حروف في الصندوق فقط.

PasswordBox and binding

عندما تريد الحصول على كلمة المرور من أداة PasswordBox، بإمكانك استخدام خاصية Password في الجزء الخاص بالبرمجة. مع ذلك ولأسباب أمنية، خاصية Password هي خاصية غير معتمدة، ما يعني أنك لا تستطيع عمل bind لها.

قد يكون هذا هاماً بالنسبة لك او قد لا يكون كذلك - كما أوضحنا ذلك مسبقاً، لا يزال بإمكانك قراءة كلمة المرور في الجزء البرمجي، لكن من أجل عمل MVVM او فقط اذا كنت من محبي data binding، تم تطوير حل لهذه المشكلة. بإمكانك قراءة المزيد حول ذلك هنا: http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html


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!