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 6791115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:48:25+00:00 2026-05-26T17:48:25+00:00

So I am trying to impliment a simple Kerning UserControl to use with DataBound

  • 0

So I am trying to impliment a simple Kerning UserControl to use with DataBound text in a ListBoxTemplate and I am getting the error that is in the title of this question.

I am using Design Time data to populate data while I am developing in VS or Expression Blend but I am not sure if this is the cause as it builds and only crashes when I populate the data.

<ListBox
            x:Name="MainList"
            ItemsSource="{Binding FeedItems}"
            SelectionChanged="ListBox_SelectionChanged"
            >
            <ListBox.ItemTemplate>

                <DataTemplate>
                    <StackPanel Orientation="Horizontal" x:Uid="{Binding ItemLink}" Margin="10">
                        <Controls:KerningTextBlock
                        Spacing="2"
                        Font="Verdana"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Left"
                        FontSize="32"
                        InputText="{Binding ItemTitle}"/>

                ....

    private StackPanel Stack = new StackPanel()
    {
        FlowDirection = System.Windows.FlowDirection.LeftToRight,
        Orientation = System.Windows.Controls.Orientation.Horizontal
    };

    private void KernIt()
    {
        // Clear the contents
        this.LayoutRoot.Children.Clear();

        // Convert input string to character array
        char[] Letters = !string.IsNullOrEmpty(this.InputText)? this.InputText.ToCharArray() : " ".ToCharArray();

        // For each item create a new text block with the following test
        foreach (var letter in Letters)
        {
            // Set up the formatted text block
            TextBlock TempText = new TextBlock();
            TempText.FontFamily = new FontFamily(this.Font);
            TempText.FontSize = 30;
            TempText.Padding = new Thickness(0, 0, this.Spacing, 0);
            TempText.Text = letter.ToString();

            // Add to the stack
            Stack.Children.Add(TempText);
        }
        // Add to the grid
        if (Stack.Children.Count() > 0)
            this.LayoutRoot.Children.Add(Stack);
    }

    public string InputText { get; set; }
    public double Spacing { get; set;}
    public string Font { get; set; }
  • 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-26T17:48:25+00:00Added an answer on May 26, 2026 at 5:48 pm

    Got it…In the user control you have to add

    DataContext="{Binding}"
    

    Then set the Layout root as follows since I am clearing out the LayoutRoot (which needs to now be changed to SubRoot.Children.Clear():

    <Grid x:Name="LayoutRoot" >
        <TextBlock x:Name="Title" Text="{Binding ItemTitle}"/>
        <Grid x:Name="SubRoot">
        </Grid>
    </Grid>
    

    Next in the code behind add an on loaded event:

    public KerningTextBlock()
    {
        UpdateLayout();
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(KerningTextBlock_Loaded);
    }
     void KerningTextBlock_Loaded(object sender, RoutedEventArgs e)
    {
         if (string.IsNullOrEmpty(Title.Text))
            this.InputText = "why am I empty?";
        else
            this.InputText = Title.Text;
        KernIt();
    }
    

    Then where you are calling the User Control change it to this:

    <Controls:KerningTextBlock
        DataContext="{Binding}"
        Spacing="5"
        Font="Verdana"
        x:Name="Button_Name"
        Margin="135,5,15,0"
        VerticalAlignment="Center"
        HorizontalAlignment="Left"
        FontSize="32"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement simple xhr abstraction, and am getting this warning when
I'm trying to implement a simple watermark on a text box that disappears when
trying to implement a simple sieve of erathosthenes to solve this question on project
I'm trying to implement a simple horizontal navigation menu that just shows a single
Trying to implement simple error handling without adding buku try / except statements to
I was trying to implement a simple function that can concatenate any number of
I'm trying to implement simple Event Bus I started like this: public class RegistrationData
I'm trying to implement simple Comet chat example and for this I implemented Long
I'm trying to implement this simple example of how to synchronize threads using pthread
I'm trying to implement a simple tagging system (messing around in php)... I use

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.