Megamax5000
Topic Author
Posts: 3
Joined: 15 Feb 2018, 22:23

Binding and Converters not working for RowDefinition Height in Unity

15 Feb 2018, 22:36

Hey there. I'm trying to Dynamically set the RowDefinition Height for a Grid. I have tried the following two methods:

Method: Binding to GridLength in ViewModel
View:
<RowDefinition x:Name="HeaderRow" Height="{Binding HeaderRowHeight}"/>
ViewModel:
private Noesis.GridLength headerRowHeight;
        public Noesis.GridLength HeaderRowHeight
        {
            get { return headerRowHeight; }
            private set
            {
                headerRowHeight = value;
                OnPropertyChanged("HeaderRowHeight");
            }
        }
HeaderRowHeight = new Noesis.GridLength(500000f);
This method of binding works elsewhere in my project on TextBlocks Text being bound to strings and Button Commands being bound to commands. In this case however, the row remains at the default value of "*".


Method: Use of Converter
View:
<RowDefinition x:Name="FooterRow" 
                Height="{Binding ActualHeight, 
                        ElementName=ProjectGrid, 
                        Converter={StaticResource SetGridLengthPercentageConverter}, 
                        ConverterParameter=10, 
                        Mode=OneWay, 
                        FallbackValue=128}"/>
Converter Code:
public class SetGridLengthPercentageConverter : IValueConverter
    {

        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string fullValueString = value.ToString();
            string percentageWantedString = parameter.ToString();

            double fullValue = System.Convert.ToDouble(fullValueString);
            double percentageWanted = System.Convert.ToDouble(percentageWantedString);

#if UNITY_5 || UNITY_5_3_OR_NEWER
            return new GridLength((float)(fullValue * (percentageWanted / 100)));
#else
            return null;
#endif
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }
    }
Error Received in Unity:
InvalidOperationException: Native type is not registered
Noesis.Extend.GetNativeTypeInfo (IntPtr nativeType) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:481)

Again, I have Converters working in other parts of the view. So it's just this one that does not work. I saw that a similar problem got fixed a couple years ago on the trello board, am I wrong to assume this still holds?
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Binding and Converters not working for RowDefinition Height in Unity

20 Feb 2018, 21:39

Could you please report it in our bugtracker, this seems like GridLength type is not working when used in bindings/converters from Unity.

Who is online

Users browsing this forum: No registered users and 1 guest