Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# How To Get Version Info Of exe in FTP Pin
Richard MacCutchan28-May-20 3:19
mveRichard MacCutchan28-May-20 3:19 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Ertuğrul ÇİÇEK28-May-20 3:41
Ertuğrul ÇİÇEK28-May-20 3:41 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard MacCutchan28-May-20 3:43
mveRichard MacCutchan28-May-20 3:43 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard Deeming28-May-20 3:53
mveRichard Deeming28-May-20 3:53 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
OriginalGriff28-May-20 3:57
mveOriginalGriff28-May-20 3:57 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Ertuğrul ÇİÇEK28-May-20 6:32
Ertuğrul ÇİÇEK28-May-20 6:32 
GeneralRe: C# How To Get Version Info Of exe in FTP Pin
Richard Deeming28-May-20 8:32
mveRichard Deeming28-May-20 8:32 
QuestionCreating and Binding UI objects in C# instead of XAML (WPF) Pin
Member 1484454026-May-20 12:04
Member 1484454026-May-20 12:04 
he application that I'm creating has a menu comprised of labels/headers. When you click on a menu item (a xaml Label) a drop down appears with subheaders related to that item. However, I need to make this menu customizable via XML. The idea is this, the XML outlines the header names as well as the subheader names for each menu item.

<MenuHeaders>
    <Header Value="Something">
        <NestedHeader1>NestedHeader1</NestedHeader1>
        <NestedHeader2>NestedHeader2</NestedHeader2>
    </Header>
    <Header Value="Something Else">
        <NestedHeader1>NestedHeader1</NestedHeader1>
        <NestedHeader2>NestedHeader2</NestedHeader2>
    </Header>
</MenuHeaders>

I am able to read the XML using XDocument and bind a Dependency Property to the label context. The problem is that I do not know how many menu items might be in the XML file. I wanted to avoid creating a ton of labels and dependency properties for the label content to bind to. Instead of creating labels in xaml and binding to a property in C#, can I create UI items in C# and populate them with elements from a list at run time? There's some code below of how I'm getting and binding the data to a preexisting label.

C#:

<pre>
 public string HeaderName
 {
      get => (string)GetValue(HeaderNameProperty);
      set => SetValue(HeaderNameProperty, value);
 }

 public static readonly DependencyProperty HeaderNameProperty =
        DependencyProperty.Register("HeaderName", typeof(string), typeof(MainWindow));

 private void LoadHeaders()
{
    var msg = new List<string>(0);
    XDocument doc = null;

    try
    {
        doc = XDocument.Load("MenuHeaders.xml");
    }
    catch (Exception e)
    {
        msg.Add(string.Format("Unable to open file:{0}", ""));
        msg.Add(e.Message);
    }

    if(doc != null)
    {
        var allHeaders = doc.Descendants("Header").ToList();
        List<string> headers = new List<string>();

        foreach(XNode node in allHeaders)
        {
            XElement element = node as XElement;
            foreach(XAttribute attribute in element.Attributes())
            {
                headers.Add(attribute.Value);
            }
        }
        HeaderName = headers[0];
    }
}

XAML:

<stackpanel x:name="Stack">


(As you may have noticed, I'm only adding the Header attributes to the List and none of the subheaders. This code is not complete but it's what I currently have) I will appreciate any help.
AnswerRe: Creating and Binding UI objects in C# instead of XAML (WPF) Pin
Mycroft Holmes26-May-20 12:26
professionalMycroft Holmes26-May-20 12:26 
AnswerRe: Creating and Binding UI objects in C# instead of XAML (WPF) Pin
Richard Deeming27-May-20 1:01
mveRichard Deeming27-May-20 1:01 
QuestionHow to mount an ISO file with disc type - CD/DVD Pin
Member 1001484126-May-20 6:43
Member 1001484126-May-20 6:43 
AnswerRe: How to mount an ISO file with disc type - CD/DVD Pin
Richard MacCutchan26-May-20 6:48
mveRichard MacCutchan26-May-20 6:48 
QuestionHow to reverse strings in other processes c# Pin
mcneb1025-May-20 11:06
mcneb1025-May-20 11:06 
AnswerRe: How to reverse strings in other processes c# Pin
Dave Kreskowiak25-May-20 18:30
mveDave Kreskowiak25-May-20 18:30 
Questionquestion about a method program Pin
Joanna Moses23-May-20 1:34
Joanna Moses23-May-20 1:34 
AnswerRe: question about a method program Pin
Richard MacCutchan23-May-20 2:00
mveRichard MacCutchan23-May-20 2:00 
AnswerRe: question about a method program Pin
OriginalGriff23-May-20 2:01
mveOriginalGriff23-May-20 2:01 
GeneralRe: question about a method program Pin
Luc Pattyn23-May-20 5:00
sitebuilderLuc Pattyn23-May-20 5:00 
GeneralRe: question about a method program Pin
OriginalGriff23-May-20 5:26
mveOriginalGriff23-May-20 5:26 
GeneralRe: question about a method program Pin
Richard MacCutchan23-May-20 5:52
mveRichard MacCutchan23-May-20 5:52 
GeneralRe: question about a method program Pin
OriginalGriff23-May-20 5:54
mveOriginalGriff23-May-20 5:54 
GeneralRe: question about a method program Pin
Richard MacCutchan23-May-20 6:08
mveRichard MacCutchan23-May-20 6:08 
GeneralRe: question about a method program Pin
OriginalGriff23-May-20 6:11
mveOriginalGriff23-May-20 6:11 
GeneralRe: question about a method program Pin
kalberts23-May-20 6:50
kalberts23-May-20 6:50 
GeneralRe: question about a method program Pin
OriginalGriff23-May-20 9:14
mveOriginalGriff23-May-20 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.