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. Custom Control Style Question

Custom Control Style Question

Scheduled Pinned Locked Moved WPF
cssdatabasewpfwcfquestion
5 Posts 2 Posters 2 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 am creating a File Picker control, which will have a caption, a textbox, and a button with an image on it. Pretty straightforward. The control will live inside a controls project I have.

        <Setter Property="Template">
    
            <Setter.Value>
    
                <ControlTemplate>
    
                    <Border x:Name="border"
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            CornerRadius="{TemplateBinding BorderThickness}">
    
                        <Grid>
    
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="\*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
    
                            <TextBlock Text="{Binding Caption}"
                                       x:Name="caption"
                                       Margin="2"/>
    
                            <TextBox Grid.Column="1"
                                     x:Name="textbox"
                                     Text="{Binding File}"/>
    
                            <Button Grid.Column="2"
                                    x:Name="button"
                                    Command="{Binding SelectedFileCommand}"/>
    
                        </Grid>
                        
                    </Border>
    
    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="button" Property="Background" Value="{StaticResource disabledBackgroundBrush}" />
                        </Trigger>
    
                    </ControlTemplate.Triggers>
                </ControlTemplate>
    
            </Setter.Value>
    
        </Setter>
    

    If you notice, I have defined a background brush for the textbox disabled state.

    L 1 Reply Last reply
    0
    • K Kevin Marois

      I am creating a File Picker control, which will have a caption, a textbox, and a button with an image on it. Pretty straightforward. The control will live inside a controls project I have.

          <Setter Property="Template">
      
              <Setter.Value>
      
                  <ControlTemplate>
      
                      <Border x:Name="border"
                              Background="{TemplateBinding Background}" 
                              BorderBrush="{TemplateBinding BorderBrush}" 
                              BorderThickness="{TemplateBinding BorderThickness}" 
                              CornerRadius="{TemplateBinding BorderThickness}">
      
                          <Grid>
      
                              <Grid.ColumnDefinitions>
                                  <ColumnDefinition Width="Auto"/>
                                  <ColumnDefinition Width="\*"/>
                                  <ColumnDefinition Width="Auto"/>
                              </Grid.ColumnDefinitions>
      
                              <TextBlock Text="{Binding Caption}"
                                         x:Name="caption"
                                         Margin="2"/>
      
                              <TextBox Grid.Column="1"
                                       x:Name="textbox"
                                       Text="{Binding File}"/>
      
                              <Button Grid.Column="2"
                                      x:Name="button"
                                      Command="{Binding SelectedFileCommand}"/>
      
                          </Grid>
                          
                      </Border>
      
      
                      <ControlTemplate.Triggers>
                          <Trigger Property="IsEnabled" Value="False">
                              <Setter TargetName="button" Property="Background" Value="{StaticResource disabledBackgroundBrush}" />
                          </Trigger>
      
                      </ControlTemplate.Triggers>
                  </ControlTemplate>
      
              </Setter.Value>
      
          </Setter>
      

      If you notice, I have defined a background brush for the textbox disabled state.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I pass anything that needs custom ("team") colors, a "custom colors" (team) object at "load" time; with "primary" and "secondary" colors and FG, BG colors, that are bound to at run time. The other option is to use "dynamic" resource references; where you play with the resource (brush) that is referenced.

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      K 1 Reply Last reply
      0
      • L Lost User

        I pass anything that needs custom ("team") colors, a "custom colors" (team) object at "load" time; with "primary" and "secondary" colors and FG, BG colors, that are bound to at run time. The other option is to use "dynamic" resource references; where you play with the resource (brush) that is referenced.

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        I don't understand that at all. Please explain

        In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.

        L 1 Reply Last reply
        0
        • K Kevin Marois

          I don't understand that at all. Please explain

          In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          It's probably not "MVVM".

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          K 1 Reply Last reply
          0
          • L Lost User

            It's probably not "MVVM".

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #5

            Huh? That's even momre confusing

            In theory, theory and practice are the same. But in practice, they never are.” If it's not broken, fix it until it is. Everything makes sense in someone's mind.

            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