Bind MinWidth of TextBox

Hello,

how can I restrict the minimum size of the default TextBox for inplace editing to the size of node’s TextBlock? I created a template for that purpose

      <DataTemplate x:Key="TextEditAdornmentTemplate">
         <TextBox MinWidth="{Binding Path=Node.AdornedElement.Width, Mode=OneTime}"/>
      </DataTemplate>

and set it to the go:Part.TextEditAdornmentTemplate attached property of the TextBlock.
However the exception is thrown at runtime:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Double d)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass1.b__0()
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at NetworkGraphControlxaml_6.BindingOperation_222_30(Object BindingState, Action )

Any suggestions are appreciated.
Thanks in advance.

Regards,
Mikhail.

The problem might be that your TextBlock.Width is NaN, which is its default value, unless you have set it.

Try Path=Node.AdornedElement.ActualWidth .

Thank you, it works greatly!

Regards,
Mikhail.