Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Need help making a dynamic control

$
0
0

Hello All,

I am working on a project and need some help with bindings...

I have a list of products, that can belong to a distribution center. I would like to create a dynamic form, ie, one that can decide for itself what content it should display, based on the availability of information.

Basically, The distribution currently have 3 products that it can report on, but that number is variable. It should display 3 entries right now, but should there be more (or less) it should be able to handle it.

For instance, I would like to bind the DistributionCenter's Name property to a type of header label, and the different product names, along with the quantity of each one, should be displayed as two labels (the dynamic part).

I hope I make sense. Here is the model code, the GUI is not implemented yet, as I do need help with that part.

namespace Stock
{
    public partial class MainWindow : Window
    {
        public class Product
        {
            // accessors
            public string Code { get; set; }
            public string Name { get; set; }
            public int Quantity { get; set; }
            private int Threshold { get; set; }

            // constructor
            public Product(string code, string name, int quantity, int threshold)
            {
                this.Code = code;
                this.Name = name;
                this.Quantity = quantity;
                this.Threshold = threshold;
            }
        }
        public class DistributionCentre
        {
            // accessors
            public string Name { get; set; }
            public List<Product> p = new List<Product>();

            // constructor
            public DistributionCentre(string name, Product product)
            {
                this.p.Add(product);
            }
        }

        public class StockEngine
        {
            public StockEngine()
            {
                // register a few products
                Product p1 = new Product("1001", "Product1", 10, 5);
                Product p2 = new Product("1002", "Product2", 6, 5);
                Product p3 = new Product("1003", "Product3", 8, 5);

                // assign these products to a DC
                DistributionCentre ClinicA = new DistributionCentre("DC1", p1);
            }
        }

        public MainWindow()
        {
            StockEngine control = new StockEngine();
            InitializeComponent();
        }
    }

Code Behind:

<UserControl x:Class="Stock.ReportingCard"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         mc:Ignorable="d"
         d:DesignHeight="37" d:DesignWidth="300"><Grid Height="35"><Label Content="Product" Height="25" HorizontalAlignment="Left" Name="Product" VerticalAlignment="Top" Width="67" Margin="5,5,0,0" /><Label Content="Quantity" Height="30" HorizontalAlignment="Left" Margin="78,5,0,0" Name="Quantity" VerticalAlignment="Top" Width="59" /><Button Content="Plus" Height="24" HorizontalAlignment="Left" Margin="171,6,0,0" Name="PlusButton" VerticalAlignment="Top" Width="44" /><Button Content="Minus" Height="24" HorizontalAlignment="Left" Margin="233,6,0,0" Name="MinusButton" VerticalAlignment="Top" Width="44" /></Grid>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>