Compartilhar via


Como: Usar um Objeto ThicknessConverter

Exemplo

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. Esse método transmite o ListBoxItem para um ThicknessConverter o objeto, que converte o Content de um ListBoxItem a uma instância de Thickness. This value is then passed back as the value of the BorderThickness property of the Border.

This example does not run.

Private Sub changeThickness(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)

    Dim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
    Dim myThicknessConverter As System.Windows.ThicknessConverter = New System.Windows.ThicknessConverter()
    Dim th1 As Thickness = CType(myThicknessConverter.ConvertFromString(li.Content.ToString()), Thickness)
    border1.BorderThickness = th1
    bThickness.Text = "Border.BorderThickness =" + li.Content.ToString()
End Sub
        private 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();
        }

Consulte também

Tarefas

Como: Change the Margin Property

Como: Convert a ListBoxItem to a New Data Type

Referência

Thickness

ThicknessConverter

Border

Conceitos

Panels Overview