Style User Control
-
I have a UserControl that contains a ListBox, a CheckBox, a TextBox, and OK & Cancel buttons. I made a few small changes to the button's control template to change the button's border and added a trigger. This control can be used an any app, so I need to understand how to style it. Would I need to name the button and create a named style? That would be in each app that I want to use it I would have to create style elements that specifically target each element in my UserControl. I'm not sure how styling works for generic UserControls. Can someone point me in the right direction? Thanks
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I have a UserControl that contains a ListBox, a CheckBox, a TextBox, and OK & Cancel buttons. I made a few small changes to the button's control template to change the button's border and added a trigger. This control can be used an any app, so I need to understand how to style it. Would I need to name the button and create a named style? That would be in each app that I want to use it I would have to create style elements that specifically target each element in my UserControl. I'm not sure how styling works for generic UserControls. Can someone point me in the right direction? Thanks
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
In this WPF can be a real pain. I wanted to create a textbox that had a browse button inside of it to match some other controls and it was quite the hassle. Basically, the flow is this: 1. Create your user control, hopefully it is based off of other controls so you can use the existing dependency properties 2. In your resources.xaml file, add a reference to the xmlns of your control 3. Add style in resources.xaml For me, my control is called a BrowseTextBox. The style looks like this:
<Setter Property="BorderThickness" Value="1" /> <Setter Property="Background" Value="#FFFFFF" /> <Setter Property="Foreground" Value="#000000" /> <Setter Property="Padding" Value="5,3" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="KeyboardNavigation.TabNavigation" Value="Once" /> <Setter Property="KeyboardNavigation.ControlTabNavigation" Value="Cycle" /> <Setter Property="IsTabStop" Value="False" /> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate /> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type cont:BrowseTextBox}"> <Grid x:Name="LayoutGrid"> <Grid.ColumnDefinitions> <ColumnDefinition x:Name="TextColumn" Width="\*" /> <ColumnDefinition x:Name="ButtonsColumn" Width="Auto" /> </Grid.ColumnDefinitions> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="MouseOver"> </x-turndown>