I wrote my custom control SearchTextBox
. This control has the property PopupContent
. PopupContent has a CheckBox and I want to bind it to the property IsChecked
But the binding does not work. How can I do this correctly?
<UserControl x:Class="TestEnv2.PanelViews.SolutionView.SolutionViewContent">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="2"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" x:Name="SearchPanel" Visibility="Hidden" Background="#efeff2" >
<ctrl:SearchTextBox x:Name="SearchControl" Height="21" BorderThickness="0" VerticalContentAlignment="Center" Background="White"
SearchMode="Delayed" LabelText="Search Solution Explorer" Search="SolutionView_Search">
<ctrl:SearchTextBox.PopupContent>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="5,0,0,0" Text="Search options" Foreground="Gray" VerticalAlignment="Center"/>
<CheckBox Grid.Row="1" Margin="5,0,0,5" Content="Match case"
IsChecked="{Binding Path=SearchMatchCase, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type panels_soln:SolutionViewContent}}}"/>
</Grid>
</ctrl:SearchTextBox.PopupContent>
</ctrl:SearchTextBox>
</Border>
</Grid>
</UserControl>
Code behind:
public partial class SolutionViewContent : UserControl
{
public static readonly DependencyProperty SearchMatchCaseProperty = DependencyProperty.
Register("SearchMatchCase", typeof(Boolean), typeof(SolutionViewContent), new UIPropertyMetadata(true));
public Boolean SearchMatchCase
{
get { return (Boolean)GetValue(SearchMatchCaseProperty); }
set
{
MessageBox.Show("SearchMatchCase");
SetValue(SearchMatchCaseProperty, value);
}
}
public SolutionViewContent()
{
InitializeComponent();
}
}