- Megamax5000
- Posts: 3
- Joined:
Binding and Converters not working for RowDefinition Height in Unity
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:
ViewModel:
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:
Converter Code:
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?
Method: Binding to GridLength in ViewModel
View:
Code: Select all
<RowDefinition x:Name="HeaderRow" Height="{Binding HeaderRowHeight}"/>
Code: Select all
private Noesis.GridLength headerRowHeight;
public Noesis.GridLength HeaderRowHeight
{
get { return headerRowHeight; }
private set
{
headerRowHeight = value;
OnPropertyChanged("HeaderRowHeight");
}
}
Code: Select all
HeaderRowHeight = new Noesis.GridLength(500000f);
Method: Use of Converter
View:
Code: Select all
<RowDefinition x:Name="FooterRow"
Height="{Binding ActualHeight,
ElementName=ProjectGrid,
Converter={StaticResource SetGridLengthPercentageConverter},
ConverterParameter=10,
Mode=OneWay,
FallbackValue=128}"/>
Code: Select all
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();
}
}
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?
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Binding and Converters not working for RowDefinition Height in Unity
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: Ahrefs [Bot], Bing [Bot] and 6 guests