これにはおそらくValueConverterを使用する必要があります。何かのようなもの:
public class LeftRightThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int)
{
int margin = (int)value;
return Thickness(margin, 0, margin, 0);
}
return Thickness();
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
その後、次の方法でコンバーターを使用できます。
<Grid>
<Grid.Resources>
<xxx:LeftRightThicknessConverter x:Key="LeftRightThicknessConverter" />
</Grid.Resources>
<Image Margin="{Binding SomePropertyPath, Converter={StaticResource LeftRightThicknessConverter}}" />
</Grid>
xxx
それが有効な xml-namespace であると仮定します。