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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:22:57+00:00 2026-06-09T11:22:57+00:00

I am trying to develop a application where-in I a want to generate a

  • 0

I am trying to develop a application where-in I a want to generate a random number after every three seconds, insert that number into a listBox and using DataTemplate display the ListBox as a rectangle.

This is for reference.

Now the problem is that I have used a DispatcherTimer which ‘ticks’ after 3 seconds but the rectangle is not updated.

I am posting my XAML and .cs code. Any hints ?

namespace ListBarGraph
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : Window
    {
        DispatcherTimer dt = new DispatcherTimer();
        DataFactory df = new DataFactory();

        public MainWindow()
        {
            InitializeComponent();
            dt.Tick += new EventHandler(dt_Tick);
            dt.Interval = new TimeSpan(0, 0, 3);
            dt.Start();

            this.PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);
        }

        void dt_Tick(object sender, EventArgs e)
        {
            df.GetData();
        }
    }

    public class DataFactory
    {
        int number = 0;

        public IEnumerable<int> GetData()
        {
            Random random = new Random();
            number = random.Next(0, 100);
            return new int[] { 0, number };
        }
    }
}




<Window x:Class="ListBarGraph.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ListBarGraph"
        Title="MainWindow" Height="350" Width="525">

   <Window.Resources>

       <ObjectDataProvider x:Key="someData" ObjectType="{x:Type local:DataFactory}" MethodName="GetData" />

      <DataTemplate x:Key="BarChartItemsTemplate">
         <Border Width="300" Height="50">
            <Grid>
               <Rectangle Fill="Red" StrokeThickness="2" Height="40" Width="{Binding}" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                  <Rectangle.LayoutTransform>
                     <ScaleTransform ScaleX="1.5"/>
                  </Rectangle.LayoutTransform>
               </Rectangle>
         </Grid>
         </Border>
      </DataTemplate>

      <ItemsPanelTemplate x:Key="BarChartItemsPanel">
         <VirtualizingStackPanel IsItemsHost="True">
            <VirtualizingStackPanel.LayoutTransform>
               <TransformGroup>
                  <RotateTransform Angle="90"/>
                  <ScaleTransform ScaleX="-1" ScaleY="1"/>
               </TransformGroup>
            </VirtualizingStackPanel.LayoutTransform>
         </VirtualizingStackPanel>
      </ItemsPanelTemplate>

 </Window.Resources>

   <Grid>
      <ListBox ItemsSource="{Binding Source={StaticResource someData}}" ItemTemplate="{DynamicResource BarChartItemsTemplate}" ItemsPanel="{DynamicResource BarChartItemsPanel}"/>

   </Grid>

</Window>
  • 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-06-09T11:23:00+00:00Added an answer on June 9, 2026 at 11:23 am

    Your XAML is bound to one instance of DataFactory as created by the ObjectProvider, whilst your code-behind creates another instance altogether, to which the UI is not bound.

    Try this to get you started. In your XAML, remove the ObjectProvider and change your ListBox to:

    <ListBox ItemsSource="{Binding}" ...
    

    Inside dt_Tick, do this:

    this.DataContext = df.GetData();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop an application that uses a number of images that
I am trying to develop an application that uses a number of images that
I was trying to develop the application that count the line of code my
I'm trying to develop an application in Delphi XE2 that will be able to
I'm trying to develop a Lync application that allows a user to select which
I am trying to develop an application and i want the sprites to erase
We are trying to develop a timeout feature in application where we want alert
I am trying to develop a simple application that polls events from a User's
I am trying to develop an application that displays lines of path of travel
I'm trying to develop a web application that mainly uses PHP but i'm using

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.