Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College



As it has already been mentioned above, a class properties (attributes) definied in a XAML file, the same with the features of an object element. Of course, it takes a number of ways because of the characteristic of this particular property.

Look at the following example for the interpretation displaying a button.

        <Window x:Class="Tulajdonságok.MainWindow"



                Title="MainWindow" Height="350" Width="525">


            <Button x:Name="Gomb"


             Width="150" Height="30"

             HorizontalAlignment="Center" VerticalAlignment="Top"

             Background="Azure" Foreground="Blue"

             FontFamily="Times New Roman" FontSize="20"

             FontStyle="Italic" FontWeight="Heavy" Opacity="0.5"/>



The Button element in the example is a „member” of the System.Windows.Controls. The features of the Button element represent the object’s properties, that is why we can assign values to the following characteristics (Content, Width, Height, HorizontalAlignment, VerticalAlignment, Background, foreground, FontFamily, FontSize, FontStyle, FontWeight, Opacity)

However, it is important to note, that the x:Name is not the feature of the Button object, but a feature which assigns a unique identifier to the object.

If an object is associated with only simple type values, can be defined with an abbreviated form shown in the example below.

<Button X:Name ="Gomb" Background = "Blue"  />

The previous button looks like this in C# language:

      Button button = new Button();

            button.Name = "Gomb";

            button.Content = "Gomb";

            button.Width = 150;

            button.Height = 30;

            button.HorizontalAlignment = HorizontalAlignment.Center;

            button.VerticalAlignment = VerticalAlignment.Top;

            button.Foreground = Brushes.Blue;

            button.Background = new SolidColorBrush(Colors.Azure);

            button.FontFamily = new FontFamily("Times New Roman");

            button.FontSize = 20;

            button.FontStyle = FontStyles.Italic;

            button.FontWeight = FontWeights.Heavy;

            button.Opacity = 0.5;