Export (0) Print
Expand All

How to: Use a ThicknessConverter Object

Example

This example shows how to create an instance of ThicknessConverter and use it to change the thickness of a border.

The example defines a custom method called changeThickness; this method first converts the contents of a ListBoxItem, as defined in a separate Extensible Application Markup Language (XAML) file, to an instance of Thickness, and later converts the content into a String. This method passes the ListBoxItem to a ThicknessConverter object, which converts the Content of a ListBoxItem to an instance of Thickness. This value is then passed back as the value of the BorderThickness property of the Border.

This example does not run. For the complete sample, see ThicknessConverter Object Sample.

public void changeThickness(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    ThicknessConverter myThicknessConverter = new ThicknessConverter();
    Thickness th1 = (Thickness)myThicknessConverter.ConvertFromString(li.Content.ToString());
    border1.BorderThickness = th1;
    bThickness.Text = "Border.BorderThickness =" + li.Content.ToString();
}

See Also

Community Additions

ADD
Show:
© 2014 Microsoft