I want to create a FilterControl in Silverlight:
[Caption] [TextBox] [Clear button]
I’d like to create it as a styleabel control, with the clear button functionality (I don’t want to leave it to the other developers), and with properties (Caption, FilterText).
But as far as I know and see, the first is a custom control, the second and the third are user control abilities.
Is it possible to create something, like that?
Here is the code of the CC:
<!-- Built-In Style for FilterControl -->
<Style TargetType="Controls:FilterControl">
<Setter Property="Template">
<Setter.Value>
<!-- ControlTemplate -->
<ControlTemplate TargetType="Controls:FilterControl">
<!-- Template's Root Visual -->
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="{TemplateBinding Height}"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<!--FilterCaption PART-->
<TextBlock x:Name="FilterCaptionTextBlock" Text="{TemplateBinding FilterCaption}" VerticalAlignment="Center" />
<!--FilterTextBox PART-->
<TextBox x:Name="FilterTextBox"
HorizontalAlignment="Center" Text="{Binding FilterText, Mode=TwoWay}" IsEnabled="{Binding IsEnabled}" VerticalAlignment="Center" />
<!--<TextBox x:Name="FilterTextBox"
HorizontalAlignment="Center" Text="{TemplateBinding FilterText}" IsEnabled="{Binding IsEnabled}" VerticalAlignment="Center" />-->
<!--ClearFilterTextButton PART-->
<Button x:Name="ClearFilterTextButton"
Content="X" IsEnabled="{TemplateBinding IsEnabled}" VerticalAlignment="Center" />
</StackPanel>
<!--VisualStateManager-->
<VisualStateManager.VisualStateGroups>
...
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
First lets be clear any
FrameworkControlincluding aUserControlcan be styled however I suspect what you may be refering to is the ability to replace the control’s template. The requires a custom templated control.The answer to your question is: yes of course it is.
You would create a custom templated control, with the default template you prefer.
Add Dependency properties to it for Caption and FilterText.
Use TemplateBinding to wire the Captiona and Filter text to the elements in the default template.
You would need to specify your template requires a TemplatePart of type
TextBox.You would write code to watch for changes in the TextBox so that the control updates its Filter property.