I had a problem, and after putting a lot of effort into trying to solve it, I asked a question on Stack Overflow.
However, I was very quickly told that my effort was not enough:
You've done zero research, and made very little effort to explain what you're trying to do. Where in the documentation for ContentControl did you find that it has columns? Why don't you back up and explain what your goal is, in plain English, instead of making up stories about random controls that you know nothing about? That XAML snippet doesn't illustrate your intent. What's "ColumnDataGrid"? People can't read your mind.
Before I asked, I searched the internet for a few days, tried various pieces of code (probably added and deleted 50 plus lines of code, both borrowed from the net and from my own attempts. I re-read a few sections in a few books I have and still could not figure it out. So my last choice was to ask on Stack Overflow and believe me, from a relative beginners perspective , asking on Stack Overflow is the ultimate, certain, definitive and absolute last resort for a way to get an answer.
There is another question that is similar to mine, but it is highly upvoted.
Why is a question, with the same basic premise as mine, upvoted so highly while my question was criticized?
The .NET Framework 3.0 introduced the WPF in 2006, and by the time the other question was asked, the technology was four years old. There should have been some answers out there at that point in time, so why did nobody comment about the lack of research then?
I'm not looking to attract upvotes by asking this question; I just want to learn without being belittled, told to try harder, research more or looked down upon. I'm really hesitant to ask questions here now.
I will post my original content as it has evolved quite a bit. That does not take away the fact that is was immediately commented as not being researched etc.
Question No. 1
Get selected value from combo box in c# wpf
i think this might be a stupid question but I can't find it on the internet.
I have just started using WPF forms instead of WF forms. In a WF form I could just do:
ComboBox.SelectedValue.toString();
and this would work fine.
How do I do this in WPF it doesn't seem to have the option.
My question:
Loop through Content Control in WPF?
How do you loop through DataControls on a WPF form.
In VBA it is as simple as concatenating the control number. eg, looping through a group of textbox controls,
Dim i As Integer For i = 1 To 30 Controls("txtbox" & i).Value = "" Next i
I have 4 DataControl columns I am trying to loop through and I tried something similar with C#, but obviously this does not work.
for (int i = 1; i < 4; i++) { Column[i].DataContext = sql.Staff_Time_TBLs.Select(item => item.Section_Data).Distinct().ToList(); }
How would you go about doing this. Do you have to build something like a collection?
Given the first bit of code in VBA, that was what I was trying to do in a C# application. Just like the first question in this post, a sample piece of code was given to display what was trying to be achieved.
I eventually found the answer was this below,
var columns = new List<ContentControl> { Column1, Column2, Column3, Column4 };
I found my mistake was that in my closest try to get do what I was trying to do was due to the fact I was leaving this piece of code out ContentControl