다음과 같이 내가 그것 Grid
를 포함하는의 ActualWidth
에 TextBox
의 Width
바인딩 오전 :WPF 변환기 이상한 행동
<TextBlock
Grid.Column="0"
Text="WorkPortalView UserControl"
TextTrimming="CharacterEllipsis"
Foreground="White"
Margin="5"
Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Converter={StaticResource textWidthConverter}, diag:PresentationTraceSources.TraceLevel=High}" />
, 내가 변환기를 사용하고 다음과 같이 :
class TextWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double? d = value as double?;
if (d == null)
return null;
return (d/2);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException("Cannot convert back");
}
}
이상한 점은 표시된 코드가 제대로 작동한다는 것입니다. 그러나 return (d/2)
문을 return (d - 75D)
으로 바꾼다면 속성 변경의 무한 루프가 시작되는 것 같습니다. 무엇에
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '429.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '429.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '354.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '354.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '441.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '441.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '366.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '366.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '453.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '453.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '378.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '378.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '465.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '465.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '390.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '390.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '477.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '477.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '402.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '402.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '489.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '489.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '414.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '414.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '501.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '501.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '426.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '426.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '513.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '513.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '438.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '438.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '525.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '525.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '450.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '450.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '537.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '537.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '462.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '462.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '549.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '549.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '474.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '474.6'
System.Windows.Data Warning: 94 : BindingExpression (hash=58235710): Got PropertyChanged event from Grid (hash=43090134) for ActualWidth
System.Windows.Data Warning: 99 : BindingExpression (hash=58235710): GetValue at level 0 from Grid (hash=43090134) using DependencyProperty(ActualWidth): '561.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=58235710): TransferValue - got raw value '561.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=58235710): TransferValue - user's converter produced '486.6'
System.Windows.Data Warning: 87 : BindingExpression (hash=58235710): TransferValue - using final value '486.6'
어떤 생각 : - 75D 여기
System.Windows.Data Warning: 71 : Lookup ancestor of type Grid: queried Grid (hash=19487651)
System.Windows.Data Warning: 70 : RelativeSource.FindAncestor found Grid (hash=19487651)
System.Windows.Data Warning: 76 : BindingExpression (hash=35097890): Activate with root item Grid (hash=19487651)
System.Windows.Data Warning: 106 : BindingExpression (hash=35097890): At level 0 - for Grid.ActualWidth found accessor DependencyProperty(ActualWidth)
System.Windows.Data Warning: 102 : BindingExpression (hash=35097890): Replace item at level 0 with Grid (hash=19487651), using accessor DependencyProperty(ActualWidth)
System.Windows.Data Warning: 99 : BindingExpression (hash=35097890): GetValue at level 0 from Grid (hash=19487651) using DependencyProperty(ActualWidth): '417.6'
System.Windows.Data Warning: 78 : BindingExpression (hash=35097890): TransferValue - got raw value '417.6'
System.Windows.Data Warning: 80 : BindingExpression (hash=35097890): TransferValue - user's converter produced '208.8'
System.Windows.Data Warning: 87 : BindingExpression (hash=35097890): TransferValue - using final value '208.8'
가 D에 대한 진단 추적 태그의 출력입니다 : 여기
/2 D에 대한 진단 추적 태그의 출력입니다 변환기의이 동작을 설명합니까?
TextBlock을 사용하여 그리드 크기를 조절할 수 있습니까? –
@Wonko : 아니요.하지만 다른 열과의 상호 작용 (두 열 모두에서 너비 = 자동)과 관련이있는 것 같습니다. 두 번째 열에 충분한 너비를 두지 않으면 트리거됩니다. 방정식을 d - 100D로 설정하면 (다른 열에 더 많은 공간이 남음) 문제를 해결하는 것으로 보입니다. 나는 여전히 다른 열의 "충분한"공간이 무엇인지 알 수있는 트리거링 조건을 알지 못하고 왜 다른 열을 잘랐는지 또는 다른 최종 결정을 내리지 않는 이유를 알지 못합니다. – Bill