1
부울 값에 따라 GridViewColumn의 너비를 값 또는 auto로 설정해야합니다.너비 = 자동 바인딩을 통해 GridViewColumn 설정하는 방법?
<GridViewColumn Width="{Binding ColumnWidth}">
public string DepotAssignmentWidth { get { return (hasBoolean) ? "50" : "auto"; } }
이 원하는 동작을 가지고 있지만, 나에게주는 구문 분석 오류 :
System.Windows.Data Error: 6 : 'SystemConvertConverter' converter failed to convert value 'auto' (type 'String'); fallback value will be used, if available. BindingExpression:Path=Removed; DataItem='Removed' (HashCode=15576908); target element is 'GridViewColumn' (HashCode=46088874); target property is 'Width' (type 'Double') FormatException:'System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.String.System.IConvertible.ToDouble(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at MS.Internal.Data.SystemConvertConverter.Convert(Object o, Type type, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'
나는 또한이 시도했습니다 작동하지 않을 수 있습니다 나는 현재이 셋업이 다음 중 하나를
public GridLength DepotAssignmentWidth { get { return (hasBoolean) ? new GridLength(50, GridUnitType.Pixel) : GridLength.Auto; } }
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Windows.GridLength' and 'System.Double'. Consider using Converter property of Binding. BindingExpression:Path=DepotAssignmentWidth; DataItem='RoutesAndDepotsPresenter' (HashCode=39457967); target element is 'GridViewColumn' (HashCode=30364822); target property is 'Width' (type 'Double')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='50' BindingExpression:Path=DepotAssignmentWidth; DataItem='RoutesAndDepotsPresenter' (HashCode=39457967); target element is 'GridViewColumn' (HashCode=30364822); target property is 'Width' (type 'Double')
그리고 이것은, 이는 제공 나에게 오류는 없지만 작동하지 않는 것 같습니다.
public double DepotAssignmentWidth { get { return (hasBoolean) ? 50 : GridLength.Auto.Value; } }
올바른 구현 방법은 무엇입니까?
게시 막이었다! 관계없이 시간을내어 주셔서 감사합니다! – Chris