1
我在下面的代碼中得到了一些隨機InvalidOperationException,有什麼解決它的好方法?InvalidOperationException從內部編輯TextBlock.Inlines OnTextChanged
public class ParsedTextBlock : TextBlock
{
static ParsedTextBlock() {
TextProperty.OverrideMetadata(typeof(ParsedTextBlock),
new FrameworkPropertyMetadata("No Text Set",
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender,
OnTextChanged)
);
}
private static void OnTextChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
ParsedTextBlock control = (ParsedTextBlock)obj;
control.Inlines.Clear();
control.Inlines.Add(new Run("test " + args.NewValue as string))
}
}
文本更改爲容器控件,它改變了子控件的文本,而不是它本身。 – Eric 2009-09-07 18:06:22