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

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. 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();
        }
    }
    
    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 Answers by the question author, which helps users to know the answer solved the author's problem.