この例では、分離コードのマージンにプロパティ値があればそれを変更することで Margin プロパティを設定する方法を示します。 Margin プロパティは、FrameworkElement 基本要素のプロパティであり、さまざまなコントロールやその他の要素によって継承されます。
この例は、XAML が参照する分離コード ファイルを含む、拡張可能なアプリケーション マークアップ言語 (XAML) で記述されています。 分離コードは C# と Microsoft Visual Basic の両方のバージョンで表示されます。
例
<Button Click="OnClick" Margin="10" Name="btn1">
Click To See Change!!</Button>
void OnClick(object sender, RoutedEventArgs e)
{
// Get the current value of the property.
Thickness marginThickness = btn1.Margin;
// If the current leftlength value of margin is set to 10 then change it to a new value.
// Otherwise change it back to 10.
if(marginThickness.Left == 10)
{
btn1.Margin = new Thickness(60);
} else {
btn1.Margin = new Thickness(10);
}
}
Private Sub OnClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Get the current value of the property.
Dim marginThickness As Thickness
marginThickness = btn1.Margin
' If the current leftlength value of margin is set to 10 then change it to a new value.
' Otherwise change it back to 10.
If marginThickness.Left = 10 Then
btn1.Margin = New Thickness(60)
Else
btn1.Margin = New Thickness(10)
End If
End Sub
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback