Maybe the title was not quite exact since I am not sure about how to describe it.
I have a user control named NSLTextBlock, below is the definition of NSLTextBlock:
public partial class NSLTextBlock: UserControl
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
public object HighlightMatchCase
{
get { return GetValue(HighlightMatchCaseProperty); }
set
{
SetValue(HighlightMatchCaseProperty, value);
}
}
public static readonly DependencyProperty HighlightMatchCaseProperty =
DependencyProperty.Register(
"HighlightMatchCase",
typeof(object),
typeof(NSLTextBlock),
new PropertyMetadata(null, new PropertyChangedCallback(HighlightChangedCallback)));
public NSLTextBlock()
{
InitializeComponent();
}
}
}
And the HighlightMatchCase is the Dependency Property.
The host view like this:
<ListView Name ="LogDataList" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding LogDataCollection}" Background="Cyan">
<ListView.View>
<GridView AllowsColumnReorder="true"
ColumnHeaderToolTip="Event Log Information">
<GridViewColumn Header="Event Log Name" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<l:NSLTextBlock Height="25" DataContext="{Binding LogName, Converter={StaticResource DataFieldConverter}}" HighlightMatchCase="{Binding Element}" Loaded="EditBox_Loaded"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Creator" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<l:NSLTextBlock Height="25" DataContext="{Binding CreatorName, Converter={StaticResource DataFieldConverter}}" HighlightMatchCase="{Binding Element}" Loaded="EditBox_Loaded"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Message" Width="100" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<l:NSLTextBlock Height="25" DataContext="{Binding Message, Converter={StaticResource DataFieldConverter}}" HighlightMatchCase="{Binding Element}" Loaded="EditBox_Loaded"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
DataField:
public class DataField : INotifyPropertyChanged
{
private HighlightElement element;
public HighlightElement Element
{
get
{ return element; }
set
{
element = value;
OnPropertyChanged("Element");
}
}
}
Actually, I want to convert the string(such as LogName, CreatorName and Message) to DataField, and binding my self-defined property(HighlightMatchCase) to Element(the converted datacontext). When I bind it to Element, it throw BindingExpressionException, cannot find property 'Element' on the object.
How can I solve it? What is your suggestion?
I really appreciate. On line'in.