1

Ok I have a way to achieve this

enter image description here

but I do way in c# like so

public partial class PlotTest
    {
        public PlotTest(double x, double y)
        {
            InitializeComponent();

            PlotControl.Margin = new Thickness(x, y, 0, 0);
        }

        public void setPlot(List<double> tempSol)
        {
            double step = (tempSol.Max() - tempSol.Min()) / 10;

            for (int ctr = 0; ctr < 10; ctr++)
            {
                TextBlock rect = (TextBlock)PlotValue.Children[ctr];
                rect.Text = (ctr == 0) ? tempSol.Max().ToString("F") :
                            (ctr == 9) ? tempSol.Min().ToString("F") : 
                            (tempSol.Max() - ctr * step).ToString("F");
                rect.TextAlignment = TextAlignment.Right;
                rect.FontSize = 10;
            }
        }
    }
}

since I do it with c# and I,m using wpf I would like to find a way to bind it to a collectionm precisely this one

 private List<double> tempsol = new List<double> {3.21, -5.41, -15.81, -21.69, -21.70, -12.60, -6.41, -0.06, 5.42, 13.32, 14.12, 7.55};

but since I'm new to wpf, xaml I'm really unsure how to do it and I can't find any solution that apply directly to my problem I could use some help thank you.

Mokmeuh
  • 865
  • 3
  • 11
  • 25

1 Answers1

2

A Grid is merely one type of Panel, however I don't think that it is the right one to select from in your situation.

At the core of things, what you want to do is visually display a sequence of values, of which they happen to be double values. When you want to visually display a sequence, you must look at an ItemsControl (or derivative of this class). From there, you can customize how each individual element is visually represented, and how the entire sequence of elements is also visually represented:

<ItemsControl ItemsSource="{Binding Path=MyCollection}">
  <ItemsControl.ItemsPanel>
    <custom:SomePanel />
  </ItemsControl.ItemsPanel>
  <ItemsControl.ItemTemplate>
    <DataTemplate>
        <!-- Some representation of each element -->
    </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

Of course, here are some supplemental reading material if you decide to roll out your own Panel:


Alternatively, you could use something that is already created out there: WPF chart controls

Community
  • 1
  • 1
myermian
  • 31,823
  • 24
  • 123
  • 215