The requirement is that the GridLength is to be set at the minimum value, although if the data in the text box increases (length of the text), it should set the value from the minimum to Auto.
//Right Now
public static readonly DependencyProperty BoxWidthProperty =
DependencyProperty.Register("BoxWidth", typeof(GridLength), typeof(ValueBox), new UIPropertyMetadata(new GridLength(80.0)));
// SomethingLike that
public static readonly DependencyProperty BoxWidthProperty =
DependencyProperty.Register("BoxWidth", typeof(GridLength), typeof(ValueBox), new UIPropertyMetadata(new GridLength(80.0,GridUnitType.Auto)));
So, what I was trying that I should able to set the default GridLength value as 80 but in case the length of the text increases, it should be able to set the value as GridUnitType.Auto.
//Field Prop
public GridLength BoxWidth
{
get
{
return (GridLength)GetValue(BoxWidthProperty);
}
set
{
SetValue(BoxWidthProperty, value);
}
}