Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1) For example i use ViewModel like this:</p> <pre><code>public enum AnswerType {OneAnswer, MultipleAnswers} public class QuestionViewModel : ViewModel { public AnswerType type; public string[] Answers; } </code></pre> <p>2) View responsibility - representing data from ViewModel: My empty view in XAML:</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="AnswerView.cs" xmlns:local="clr-namespace:sdkControlTiltEffect" mc:Ignorable="d" d:DesignHeight="173" d:DesignWidth="173"&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>I inject my ViewModel to View as constructor parameter. You cfn use DataContext instead. My dynamic view background class:</p> <pre><code>public class AnswerView : UserControl { public AnswerView(QuestionViewModel q) { switch(q.Type) { case AnswerType.OneAnswer: //Put log for jne answer view generation break; case AnswerType.MultipleAnswers: //Put logic for multiple answers View generation break; default: } } } </code></pre> <p>You should never create view elements in ViewModel. It ruins MVVM in fundamentals. ViewModel must be independent from View.</p> <p>I think it should be helpfull: <a href="https://stackoverflow.com/questions/18560776/mvvm-and-dynamic-geneation-of-controls">MVVM and dynamic generation of controls</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload