Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Style User Control

Style User Control

Scheduled Pinned Locked Moved WPF
databasehelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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.

    E 1 Reply Last reply
    0
    • K Kevin Marois

      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.

      E Offline
      E Offline
      eddieangel
      wrote on last edited by
      #2

      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>
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups