Initialize Textblock after changing Inlines [modified]
-
Hello everyone Since Inlines (CollectionInlines) arnt a dependencyproperty i made a TextBox with dependency Inlines, the Code:
public InlineCollection InlineCollection
{
get
{
return (InlineCollection)GetValue(InlineCollectionProperty);
}
set
{
SetValue(InlineCollectionProperty, value);
}
}public static readonly DependencyProperty InlineCollectionProperty = DependencyProperty.Register( "InlineCollection", typeof(InlineCollection), typeof(InlineTextBlock), new UIPropertyMetadata((PropertyChangedCallback)((sender, args) => { InlineTextBlock textBlock = sender as InlineTextBlock; if (textBlock != null) { textBlock.Inlines.Clear(); InlineCollection inlines = args.NewValue as InlineCollection; InlineCollection oldinlines = args.OldValue as InlineCollection; if (inlines != null) { textBlock.Inlines.AddRange(inlines.ToList()); } else textBlock.Inlines.AddRange(oldinlines.ToList()); } })));
The TextBlock has normally some text after that it gets new inlines, if the Inlines it gets are empty it should get its first(default) text again. Now the Problem: if it had a the first a text via Inlines then everything is ok coz i can get them again with the oldvalue, if it has a the first normal text with no inlines then the textblock doesnt show nothing because of: textBlock.Inlines.AddRange(oldinlines.ToList()); (no oldvalue of the Inlines) how can i set the first text at the ende if in this case? any ideas? Thanks in Advance. Cheers Def.
modified on Tuesday, April 12, 2011 9:02 AM