locked
How can we find a Stack panel id from the view model through code behind... RRS feed

  • Question

  • How can we find a Stack panel id from the view model through code behind...
    Saturday, May 17, 2014 1:09 PM

Answers

  • A view model should not know anything about a StackPanel or any other element in the view, this violates the MVVM pattern.

    And what do you mean by "id"? It's hard to be able to answer your question based on your very weak description of the issue and the lack of any code snippets. If you want to be able to reference a StackPanel from the code-behind of a view, you should give it an x:Name attribute in XAML and then use this name to reference it in the code:

    XAML:

    <StackPanel x:Name="stackPanel">

    Code-behind:

    StackPanel stackPanel = this.stackPanel;
    stackPanel.Children.Add(new TextBlock { Text = "..." });

    Please share more details about your issue and all relevant code snippets for anyone to be able to help you any further.

    Saturday, May 17, 2014 1:21 PM