As someone else pointed out, Inlines
is not a Dependency Property
which is why you are getting that error. When I've run across similar situations in the past, I've found Attached Properties
/Behaviors
to be a good solution. I'm going to assume that FName
is of type string
, and consequently so is the attached property. Here's an example:
class InlinesBehaviors
{
public static readonly DependencyProperty BoldInlinesProperty =
DependencyProperty.RegisterAttached(
"BoldInlines", typeof(string), typeof(InlinesBehaviors),
new PropertyMetadata(default(string), OnBoldInlinesChanged));
private static void OnBoldInlinesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var textBlock = d as TextBlock;
if (textBlock != null)
{
string fName = (string) e.NewValue; // value of FName
// You can modify Inlines in here
..........
}
}
public static void SetBoldInlines(TextBlock element, string value)
{
element.SetValue(BoldInlinesProperty, value);
}
public static string GetBoldInlines(TextBlock element)
{
return (string) element.GetValue(BoldInlinesProperty);
}
}
You could then use this in the following way (my
is the xml namespace pointing to the namespace containing the AttachedProperty
):
<TextBlock my:InlinesBehaviors.BoldInlines="{Binding FName}" />
The binding above could have been a multi binding, you could have used a converter, or whatever. Attached Behaviors
are pretty powerful and this seems like a good place to use them.
Also, in case you're interested, here's an article on Attached Behaviors
.