Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4584296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:20:04+00:00 2026-05-21T21:20:04+00:00

I’m in the process of creating a control to represent a employee work shift.

  • 0

I’m in the process of creating a control to represent a employee work shift. The shift can be of different lengths and with none or more breaks.

Mockup prototype GUI of a 9 hour work shift with an 1 hour break
Mockup prototype GUI of a 9 hour work shift with an 1 hour break

The following questions refer to the blue bar in the prototype:
Since the control need to resize perfectly, then a fixed size approach is not an option. My first thought was to use a grid with columns that has the same width ratio as the time spans. So if you look at the prototype above there would be 3 columns with a width of: 240*, 60*, 240*. These numbers are equal to the total minutes of each time span.

If I add a dependency property that hold, lets call them TimeSpanItems (TSI). Each TSI has a TimeSpan property. Is it then possible to bind this to the grid and its column definitions? The number of columns must change as TSI are added and also each column must change its width ratio to match the number of minutes.

Am I thinking about this the wrong way? Is it doable? Or is it a items control that I need that resizes its items when the control is resized?

At the moment I have different questions that I yet haven’t found the answer to… and probably a lot of questions that I don’t know yet what they are. Any help would be most welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:20:05+00:00Added an answer on May 21, 2026 at 9:20 pm

    I’m going to answer the question: Is it doable? My initial thought was that I didn’t want the calculate the resizing. I wanted a grid to solve this for me. So I am going to ignore all the other questions regarding if this should be another control type or if this the “right” way to do it.

    Here goes… first I use a control template where the uxMainContentGrid is the grid that is going to be modified when items are added.

    <Style TargetType="{x:Type wpflib:RatioPresenterControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type wpflib:RatioPresenterControl}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Height="{TemplateBinding Height}"
                        Width="{TemplateBinding Width}">
    
                    <Grid x:Name="uxMainContentGrid">
                        <Grid.ColumnDefinitions>
                            <!-- Columns and ratio is set in code behind -->
                        </Grid.ColumnDefinitions>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    

    The items that I used to set the width ratio look like this.

    Public Class RatioItem
        Public Property Value As Double
        Public Property Brush As Brush
    End Class
    

    And the RatioItems are added through this dependency property with a default value of an empty list of RatioItems.

     Public Shared ReadOnly RatioItemsProperty As DependencyProperty = _
            DependencyProperty.Register("RatioItems", GetType(IEnumerable(Of RatioItem)),
                  GetType(RatioPresenterControl),
                  New FrameworkPropertyMetadata(New List(Of RatioItem), AddressOf OnRatioItemsPropertyChanged))
    

    The dependency property that has the following value changed callback method. When you bind to the dependency property, then this callback fires before the template has been applied. This callback only reconstructs the grid columns if the control template has been set.

    Public Shared Sub OnRatioItemsPropertyChanged(sender As Object, e As DependencyPropertyChangedEventArgs)
        If (_MainContentGrid IsNot Nothing) Then
            Dim ratioItems As IEnumerable(Of RatioItem) = TryCast(e.NewValue, IEnumerable(Of RatioItem))
    
            ReconstructGridColumns(ratioItems, _MainContentGrid)
        End If
    End Sub
    

    The following code retrieves the grid when the control template is applied. The thing here is to store the grid so that it can be accessed later if the RatioItems property change. When the template is applied the binding is already in affect so the grid columns are constructed.

    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
    
        _MainContentGrid = TryCast(Me.Template.FindName("uxMainContentGrid", Me), Grid)
    
        ReconstructGridColumns(Me.RatioItems, _MainContentGrid)
    End Sub
    

    This method does all the “constructing”…

    Private Shared Sub ReconstructGridColumns(ByVal ratioItems As IEnumerable(Of RatioItem), ByVal mainContentGrid As Grid)
        Dim newContent As Rectangle
        Dim columnCount As Integer = 0
    
        mainContentGrid.ColumnDefinitions.Clear()
    
        For Each item In ratioItems
            mainContentGrid.ColumnDefinitions.Add(New ColumnDefinition() With {.Width = New GridLength(item.Value, GridUnitType.Star)})
            newContent = New Rectangle() With {.Name = "item" & columnCount, .Fill = item.Brush}
            mainContentGrid.Children.Add(newContent)
            Grid.SetColumn(newContent, columnCount)
            columnCount += 1
        Next
    End Sub
    

    And there you have it. It can be done. Now to the discussion whether it is the “right” way to do it… 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.