Share via

Binding left of margin

Shay Wilner 1,746 Reputation points
2020-06-28T17:06:26.017+00:00

Hi

I try to bind the left of margin but get syntax error

Margin="{x:Bind Path= classsize.widtharea} , 20 ,0 ,0 "

Thanks

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments

Answer accepted by question author

Daniele 1,996 Reputation points
2020-06-28T17:18:32.123+00:00

You can use a converter:

<Page.Resources>
    <local:MarginConverter x:Key="MarginConverter" />
</Page.Resources>

[...]

Margin="{x:Bind classsize, Converter={StaticResource MarginConverter}}"

converter implementation, replace YourClass with your actual class

public class MarginConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        var classsize = (YourClass)value;
        return new Thickness(classsize.widtharea, 20, 0, 0);
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.