Binding list elements with label code behindHow to set a binding in Code?How to enable assembly bind failure logging (Fusion) in .NETPerformance impact of Wpf Binding Path=x:Static <propertypath>?WPF Binding to TooltipMVVM binding properties and subpropertiesTry-catch speeding up my code?Why not inherit from List<T>?Array of textbox and labels how to get value in submit method in c#WPF Binding a label with propertiesWPF StringFormat in Binding doesn't work in code behindBinding Lists of Elements to an DataGrid

Weird resistor with dots around it

Is there a way to proportionalize fixed costs in a MILP?

Why aren't rainbows blurred-out into nothing after they are produced?

Letting unbanned users comment

How can I find an old paper when the usual methods fail?

How to not forget things?

Global BGP Routing only by only importing supernet prefixes

What would it take to get a message to another star?

Should I leave building the database for the end?

How did Arecibo detect methane lakes on Titan, and image Saturn's rings?

Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?

How was the murder committed?

Are there any cons in using rounded corners for bar graphs?

Why does the cable resistance jump from a low value to high value at a particular frequency?

Transition to "Starvation Mode" in Survival Situations

Why aren’t there water shutoff valves for each room?

What unique challenges/limitations will I face if I start a career as a pilot at 45 years old?

What is the farthest a camera can see?

In the movie Krull, what happened in the Spider Den?

Go to last file in vim

Luggage Storage at Szechenyi Baths

Cases with long math equation

How would you translate this? バタコチーズライス

Why did IBM make the PC BIOS source code public?



Binding list elements with label code behind


How to set a binding in Code?How to enable assembly bind failure logging (Fusion) in .NETPerformance impact of Wpf Binding Path=x:Static <propertypath>?WPF Binding to TooltipMVVM binding properties and subpropertiesTry-catch speeding up my code?Why not inherit from List<T>?Array of textbox and labels how to get value in submit method in c#WPF Binding a label with propertiesWPF StringFormat in Binding doesn't work in code behindBinding Lists of Elements to an DataGrid






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm try to bind struct list with labels that created dynamically.



code of structure:



public struct PrinterToGridBinds

public string extPrinterName get; set;
public string extIcecreamType get; set;
public string extBatchNumber get; set;
public string extBeginingDate get; set;
public string extPrinterState get; set;
public string extBatchCounter get; set;
public string extDIOCounter get; set;

public PrinterToGridBinds(string extPrinterName, string extIcecreamType, string extBatchNumber, string extBeginingDate,
string extPrinterState, string extBatchCounter, string extDIOCounter)

this.extPrinterName = extPrinterName;
this.extIcecreamType = extIcecreamType;
this.extBatchNumber = extBatchNumber;
this.extBeginingDate = extBeginingDate;
this.extPrinterState = extPrinterState;
this.extBatchCounter = extBatchCounter;
this.extDIOCounter = extDIOCounter;



public List<PrinterToGridBinds> lst_PrinterToGridBindings = new List<PrinterToGridBinds>();


Initialize list of structures



private void PrinterToGridBindingInit()

for (int i = 0; i < PrinterNumber; i++)

lst_PrinterToGridBindings.Add(new PrinterToGridBinds("Num " + (i + 1).ToString(), "-", "-", "-", "-", "-", "-"));




and try to bind this with labels that creating dynamically. Code below:



for (int i = 0; i < 8; i++)

Label lbl_PrinterName = new Label();
lbl_PrinterName.Name = "Name_" + i.ToString();
Binding lbl_Binding = new Binding Path = new PropertyPath(lst_PrinterToGridBindings[i].extPrinterName), Mode = BindingMode.OneWay ;
lbl_PrinterName.SetBinding(Label.ContentProperty, lbl_Binding);

Grid.SetRow(lbl_PrinterName, i + 2);
Grid.SetColumn(lbl_PrinterName, 3);
grd_WorkArea.Children.Add(lbl_PrinterName);



And I don't see any result after program runs. From other side, if I define property



public string PropName1 get; set; = "PropTest";


and add this property to binding like this:



Binding lbl_Binding = new Binding Path = new PropertyPath("PropName1"), Mode = BindingMode.OneWay ;


All works like a charm! Where is my mistake?How to bind structure data with labels dynamically?










share|improve this question






























    0















    I'm try to bind struct list with labels that created dynamically.



    code of structure:



    public struct PrinterToGridBinds

    public string extPrinterName get; set;
    public string extIcecreamType get; set;
    public string extBatchNumber get; set;
    public string extBeginingDate get; set;
    public string extPrinterState get; set;
    public string extBatchCounter get; set;
    public string extDIOCounter get; set;

    public PrinterToGridBinds(string extPrinterName, string extIcecreamType, string extBatchNumber, string extBeginingDate,
    string extPrinterState, string extBatchCounter, string extDIOCounter)

    this.extPrinterName = extPrinterName;
    this.extIcecreamType = extIcecreamType;
    this.extBatchNumber = extBatchNumber;
    this.extBeginingDate = extBeginingDate;
    this.extPrinterState = extPrinterState;
    this.extBatchCounter = extBatchCounter;
    this.extDIOCounter = extDIOCounter;



    public List<PrinterToGridBinds> lst_PrinterToGridBindings = new List<PrinterToGridBinds>();


    Initialize list of structures



    private void PrinterToGridBindingInit()

    for (int i = 0; i < PrinterNumber; i++)

    lst_PrinterToGridBindings.Add(new PrinterToGridBinds("Num " + (i + 1).ToString(), "-", "-", "-", "-", "-", "-"));




    and try to bind this with labels that creating dynamically. Code below:



    for (int i = 0; i < 8; i++)

    Label lbl_PrinterName = new Label();
    lbl_PrinterName.Name = "Name_" + i.ToString();
    Binding lbl_Binding = new Binding Path = new PropertyPath(lst_PrinterToGridBindings[i].extPrinterName), Mode = BindingMode.OneWay ;
    lbl_PrinterName.SetBinding(Label.ContentProperty, lbl_Binding);

    Grid.SetRow(lbl_PrinterName, i + 2);
    Grid.SetColumn(lbl_PrinterName, 3);
    grd_WorkArea.Children.Add(lbl_PrinterName);



    And I don't see any result after program runs. From other side, if I define property



    public string PropName1 get; set; = "PropTest";


    and add this property to binding like this:



    Binding lbl_Binding = new Binding Path = new PropertyPath("PropName1"), Mode = BindingMode.OneWay ;


    All works like a charm! Where is my mistake?How to bind structure data with labels dynamically?










    share|improve this question


























      0












      0








      0








      I'm try to bind struct list with labels that created dynamically.



      code of structure:



      public struct PrinterToGridBinds

      public string extPrinterName get; set;
      public string extIcecreamType get; set;
      public string extBatchNumber get; set;
      public string extBeginingDate get; set;
      public string extPrinterState get; set;
      public string extBatchCounter get; set;
      public string extDIOCounter get; set;

      public PrinterToGridBinds(string extPrinterName, string extIcecreamType, string extBatchNumber, string extBeginingDate,
      string extPrinterState, string extBatchCounter, string extDIOCounter)

      this.extPrinterName = extPrinterName;
      this.extIcecreamType = extIcecreamType;
      this.extBatchNumber = extBatchNumber;
      this.extBeginingDate = extBeginingDate;
      this.extPrinterState = extPrinterState;
      this.extBatchCounter = extBatchCounter;
      this.extDIOCounter = extDIOCounter;



      public List<PrinterToGridBinds> lst_PrinterToGridBindings = new List<PrinterToGridBinds>();


      Initialize list of structures



      private void PrinterToGridBindingInit()

      for (int i = 0; i < PrinterNumber; i++)

      lst_PrinterToGridBindings.Add(new PrinterToGridBinds("Num " + (i + 1).ToString(), "-", "-", "-", "-", "-", "-"));




      and try to bind this with labels that creating dynamically. Code below:



      for (int i = 0; i < 8; i++)

      Label lbl_PrinterName = new Label();
      lbl_PrinterName.Name = "Name_" + i.ToString();
      Binding lbl_Binding = new Binding Path = new PropertyPath(lst_PrinterToGridBindings[i].extPrinterName), Mode = BindingMode.OneWay ;
      lbl_PrinterName.SetBinding(Label.ContentProperty, lbl_Binding);

      Grid.SetRow(lbl_PrinterName, i + 2);
      Grid.SetColumn(lbl_PrinterName, 3);
      grd_WorkArea.Children.Add(lbl_PrinterName);



      And I don't see any result after program runs. From other side, if I define property



      public string PropName1 get; set; = "PropTest";


      and add this property to binding like this:



      Binding lbl_Binding = new Binding Path = new PropertyPath("PropName1"), Mode = BindingMode.OneWay ;


      All works like a charm! Where is my mistake?How to bind structure data with labels dynamically?










      share|improve this question














      I'm try to bind struct list with labels that created dynamically.



      code of structure:



      public struct PrinterToGridBinds

      public string extPrinterName get; set;
      public string extIcecreamType get; set;
      public string extBatchNumber get; set;
      public string extBeginingDate get; set;
      public string extPrinterState get; set;
      public string extBatchCounter get; set;
      public string extDIOCounter get; set;

      public PrinterToGridBinds(string extPrinterName, string extIcecreamType, string extBatchNumber, string extBeginingDate,
      string extPrinterState, string extBatchCounter, string extDIOCounter)

      this.extPrinterName = extPrinterName;
      this.extIcecreamType = extIcecreamType;
      this.extBatchNumber = extBatchNumber;
      this.extBeginingDate = extBeginingDate;
      this.extPrinterState = extPrinterState;
      this.extBatchCounter = extBatchCounter;
      this.extDIOCounter = extDIOCounter;



      public List<PrinterToGridBinds> lst_PrinterToGridBindings = new List<PrinterToGridBinds>();


      Initialize list of structures



      private void PrinterToGridBindingInit()

      for (int i = 0; i < PrinterNumber; i++)

      lst_PrinterToGridBindings.Add(new PrinterToGridBinds("Num " + (i + 1).ToString(), "-", "-", "-", "-", "-", "-"));




      and try to bind this with labels that creating dynamically. Code below:



      for (int i = 0; i < 8; i++)

      Label lbl_PrinterName = new Label();
      lbl_PrinterName.Name = "Name_" + i.ToString();
      Binding lbl_Binding = new Binding Path = new PropertyPath(lst_PrinterToGridBindings[i].extPrinterName), Mode = BindingMode.OneWay ;
      lbl_PrinterName.SetBinding(Label.ContentProperty, lbl_Binding);

      Grid.SetRow(lbl_PrinterName, i + 2);
      Grid.SetColumn(lbl_PrinterName, 3);
      grd_WorkArea.Children.Add(lbl_PrinterName);



      And I don't see any result after program runs. From other side, if I define property



      public string PropName1 get; set; = "PropTest";


      and add this property to binding like this:



      Binding lbl_Binding = new Binding Path = new PropertyPath("PropName1"), Mode = BindingMode.OneWay ;


      All works like a charm! Where is my mistake?How to bind structure data with labels dynamically?







      c# wpf binding






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 10:52









      AlexAlex

      1301 gold badge4 silver badges14 bronze badges




      1301 gold badge4 silver badges14 bronze badges

























          2 Answers
          2






          active

          oldest

          votes


















          1














          Seems like, for your working sample (with PropName) you define the property name in property path, but for printers you define a property value lst_PrinterToGridBindings[i].extPrinterName. Have a look at msdn. You also should specify the Source for binding






          share|improve this answer



























          • thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

            – Alex
            Mar 27 at 11:05











          • @Alex You also should specify the Source for binding, according this

            – Pavel Anikhouski
            Mar 27 at 11:11






          • 1





            Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

            – Alex
            Mar 27 at 11:43


















          0














          In order to show a list of elements, use an ItemsControl. Assign or bind its ItemsSource property to a collection of item objects. Set its ItemTemplate to a DataTemplate with UI elements that bind to properties of the item class.



          <ItemsControl x:Name="printerList">
          <ItemsControl.ItemTemplate>
          <DataTemplate>
          <TextBlock Text="Binding extPrinterName"/>
          </DataTemplate>
          </ItemsControl.ItemTemplate>
          </ItemsControl>


          Code behind:



          printerList.ItemsSource = lst_PrinterToGridBindings;


          For details, see Data Templating Overview.






          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55375438%2fbinding-list-elements-with-label-code-behind%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Seems like, for your working sample (with PropName) you define the property name in property path, but for printers you define a property value lst_PrinterToGridBindings[i].extPrinterName. Have a look at msdn. You also should specify the Source for binding






            share|improve this answer



























            • thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

              – Alex
              Mar 27 at 11:05











            • @Alex You also should specify the Source for binding, according this

              – Pavel Anikhouski
              Mar 27 at 11:11






            • 1





              Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

              – Alex
              Mar 27 at 11:43















            1














            Seems like, for your working sample (with PropName) you define the property name in property path, but for printers you define a property value lst_PrinterToGridBindings[i].extPrinterName. Have a look at msdn. You also should specify the Source for binding






            share|improve this answer



























            • thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

              – Alex
              Mar 27 at 11:05











            • @Alex You also should specify the Source for binding, according this

              – Pavel Anikhouski
              Mar 27 at 11:11






            • 1





              Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

              – Alex
              Mar 27 at 11:43













            1












            1








            1







            Seems like, for your working sample (with PropName) you define the property name in property path, but for printers you define a property value lst_PrinterToGridBindings[i].extPrinterName. Have a look at msdn. You also should specify the Source for binding






            share|improve this answer















            Seems like, for your working sample (with PropName) you define the property name in property path, but for printers you define a property value lst_PrinterToGridBindings[i].extPrinterName. Have a look at msdn. You also should specify the Source for binding







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 27 at 12:02

























            answered Mar 27 at 11:02









            Pavel AnikhouskiPavel Anikhouski

            1,4253 gold badges12 silver badges19 bronze badges




            1,4253 gold badges12 silver badges19 bronze badges















            • thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

              – Alex
              Mar 27 at 11:05











            • @Alex You also should specify the Source for binding, according this

              – Pavel Anikhouski
              Mar 27 at 11:11






            • 1





              Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

              – Alex
              Mar 27 at 11:43

















            • thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

              – Alex
              Mar 27 at 11:05











            • @Alex You also should specify the Source for binding, according this

              – Pavel Anikhouski
              Mar 27 at 11:11






            • 1





              Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

              – Alex
              Mar 27 at 11:43
















            thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

            – Alex
            Mar 27 at 11:05





            thank you for the answer. I tried do it like name with quotes, but this is doesn't work because of variable "i".

            – Alex
            Mar 27 at 11:05













            @Alex You also should specify the Source for binding, according this

            – Pavel Anikhouski
            Mar 27 at 11:11





            @Alex You also should specify the Source for binding, according this

            – Pavel Anikhouski
            Mar 27 at 11:11




            1




            1





            Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

            – Alex
            Mar 27 at 11:43





            Oh, yes! I'm forget about this absolutely. Changed my code to Binding lbl_Binding = new Binding Source = lst_PrinterToGridBindings[i], Path = new PropertyPath("extPrinterName"), Mode = BindingMode.OneWay ; And this is works properly. Many thanks!

            – Alex
            Mar 27 at 11:43













            0














            In order to show a list of elements, use an ItemsControl. Assign or bind its ItemsSource property to a collection of item objects. Set its ItemTemplate to a DataTemplate with UI elements that bind to properties of the item class.



            <ItemsControl x:Name="printerList">
            <ItemsControl.ItemTemplate>
            <DataTemplate>
            <TextBlock Text="Binding extPrinterName"/>
            </DataTemplate>
            </ItemsControl.ItemTemplate>
            </ItemsControl>


            Code behind:



            printerList.ItemsSource = lst_PrinterToGridBindings;


            For details, see Data Templating Overview.






            share|improve this answer





























              0














              In order to show a list of elements, use an ItemsControl. Assign or bind its ItemsSource property to a collection of item objects. Set its ItemTemplate to a DataTemplate with UI elements that bind to properties of the item class.



              <ItemsControl x:Name="printerList">
              <ItemsControl.ItemTemplate>
              <DataTemplate>
              <TextBlock Text="Binding extPrinterName"/>
              </DataTemplate>
              </ItemsControl.ItemTemplate>
              </ItemsControl>


              Code behind:



              printerList.ItemsSource = lst_PrinterToGridBindings;


              For details, see Data Templating Overview.






              share|improve this answer



























                0












                0








                0







                In order to show a list of elements, use an ItemsControl. Assign or bind its ItemsSource property to a collection of item objects. Set its ItemTemplate to a DataTemplate with UI elements that bind to properties of the item class.



                <ItemsControl x:Name="printerList">
                <ItemsControl.ItemTemplate>
                <DataTemplate>
                <TextBlock Text="Binding extPrinterName"/>
                </DataTemplate>
                </ItemsControl.ItemTemplate>
                </ItemsControl>


                Code behind:



                printerList.ItemsSource = lst_PrinterToGridBindings;


                For details, see Data Templating Overview.






                share|improve this answer













                In order to show a list of elements, use an ItemsControl. Assign or bind its ItemsSource property to a collection of item objects. Set its ItemTemplate to a DataTemplate with UI elements that bind to properties of the item class.



                <ItemsControl x:Name="printerList">
                <ItemsControl.ItemTemplate>
                <DataTemplate>
                <TextBlock Text="Binding extPrinterName"/>
                </DataTemplate>
                </ItemsControl.ItemTemplate>
                </ItemsControl>


                Code behind:



                printerList.ItemsSource = lst_PrinterToGridBindings;


                For details, see Data Templating Overview.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 11:20









                ClemensClemens

                93.6k8 gold badges97 silver badges192 bronze badges




                93.6k8 gold badges97 silver badges192 bronze badges






























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55375438%2fbinding-list-elements-with-label-code-behind%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript