Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Canvas.GetRight Method

Gets the value of the Right attached property for a given dependency object.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)

[TypeConverterAttribute("System.Windows.LengthConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")] 
[AttachedPropertyBrowsableForChildrenAttribute] 
public static double GetRight (
	UIElement element
)
/** @attribute TypeConverterAttribute("System.Windows.LengthConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null") */ 
/** @attribute AttachedPropertyBrowsableForChildrenAttribute() */ 
public static double GetRight (
	UIElement element
)
TypeConverterAttribute("System.Windows.LengthConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null") 
AttachedPropertyBrowsableForChildrenAttribute 
public static function GetRight (
	element : UIElement
) : double
You cannot use methods in XAML.

Parameters

element

The element from which the property value is read.

Return Value

The Right coordinate of the specified element.

This example shows how to use the positioning methods of the Canvas element to position child content. This example uses content in a ListBoxItem to represent positioning values and converts the values into instances of Double, which is a required argument for positioning. The values are then converted back into strings and displayed as text in a TextBlock element by using the GetLeft method.

The following example creates a ListBox element that has eleven selectable ListBoxItem elements. The SelectionChanged event triggers the ChangeLeft custom method, which the subsequent code block defines.

Each ListBoxItem represents a Double value, which is one of the arguments that the SetLeft method of Canvas accepts. In order to use a ListBoxItem to represent an instance of Double, you must first convert the ListBoxItem to the correct data type.

<ListBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Width="60" Margin="10,0,0,0" SelectionChanged="ChangeLeft">
  <ListBoxItem>Auto</ListBoxItem>      
  <ListBoxItem>10</ListBoxItem>
  <ListBoxItem>20</ListBoxItem>
  <ListBoxItem>30</ListBoxItem>
  <ListBoxItem>40</ListBoxItem>
  <ListBoxItem>50</ListBoxItem>
  <ListBoxItem>60</ListBoxItem>
  <ListBoxItem>70</ListBoxItem>
  <ListBoxItem>80</ListBoxItem>
  <ListBoxItem>90</ListBoxItem>
  <ListBoxItem>100</ListBoxItem>      
</ListBox>

<ListBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Width="60" Margin="10,0,0,0" SelectionChanged="ChangeLeft">
  <ListBoxItem>Auto</ListBoxItem>      
  <ListBoxItem>10</ListBoxItem>
  <ListBoxItem>20</ListBoxItem>
  <ListBoxItem>30</ListBoxItem>
  <ListBoxItem>40</ListBoxItem>
  <ListBoxItem>50</ListBoxItem>
  <ListBoxItem>60</ListBoxItem>
  <ListBoxItem>70</ListBoxItem>
  <ListBoxItem>80</ListBoxItem>
  <ListBoxItem>90</ListBoxItem>
  <ListBoxItem>100</ListBoxItem>      
</ListBox>

When a user changes the ListBox selection, it invokes the ChangeLeft custom method. This method passes the ListBoxItem to a LengthConverter object, which converts the Content of a ListBoxItem to an instance of Double (notice that this value has already been converted to a String by using the ToString method). This value is then passed back to the SetLeft and GetLeft methods of Canvas in order to change the position of the text1 object.

public void ChangeLeft(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    LengthConverter myLengthConverter = new LengthConverter();
    Double db1 = (Double)myLengthConverter.ConvertFromString(li.Content.ToString());
    Canvas.SetLeft(text1, db1);
    String st1 = (String)myLengthConverter.ConvertToString(Canvas.GetLeft(text1));
    canvasLeft.Text = "Canvas.Left = " + st1;
}

For the complete sample, see Positioning Properties of Canvas Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2014 Microsoft