Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How I'd do this:</p> <p>I'd start by building a simple view-model class that wraps around an <code>XmlElement</code> and exposes it as a configuration option. This class could be <em>extremely</em> simple, e.g.:</p> <pre><code>public class OptionView { private XmlElement XmlElement; public OptionView(XmlElement xmlElement) { XmlElement = xmlElement; } public string Name { get { return XmlElement.Name; } } public string Value { get { return XmlElement.InnerText; } set { XmlElement.InnerText = value; } } } </code></pre> <p>Now I can populate a collection of <code>ElementView</code> objects from an <code>XmlDocument</code>, add that collection to the window's <code>ResourceDictionary</code>, and format the objects with a simple <code>DataTemplate</code>, e.g.:</p> <pre><code>&lt;DataTemplate x:Key="OptionViewTemplate" DataType={x:Type local:OptionView}&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition SharedSizeGroup="Name"/&gt; &lt;ColumnDefinition SharedSizeGroup="Value"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Label Content="{Binding Name}" Grid.Column="0"/&gt; &lt;TextBox Text="{Binding Value}" Grid.Column="1"/&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; ... &lt;ItemsControl Grid.IsSharedSizeScope="True" ItemsSource="{DynamicResource OptionCollection}"/&gt; </code></pre> <p>(Note: Later, you can get fancy, and define subclasses of <code>OptionView</code> based on, for instance, the data type of the underlying <code>XmlElement</code>. Then you can define <code>DataTemplate</code>s for each subclass, and as long as each presents the item in a two-column grid using that <code>SharedSizeGroup</code>, the second column can contain a date picker, or radio buttons, or whatever is appropriate to the subclass, and it'll all get neatly laid out at runtime.)</p> <p>Once I got that working, which wouldn't take long, I'd start extending the <code>OptionView</code> class. For instance, if your schema is storing a human-readable label for an element in an <code>xs:annotation</code> element (and if it isn't, why not?), I'd make the <code>Name</code> property extract that out of the <code>XmlElement</code>'s <code>SchemaInfo</code> property, instead of exposing the underlying element name. </p> <p>Obviously I'd want to add validation, so I'd add a validation method that examined the <code>XmlElement</code>'s <code>SchemaInfo</code> property and interpreted it. (Assuming that the elements you're validating are simple content, that shouldn't be hard.) There's a million tutorials on how to implement validation in WPF applications, so I won't go into too much detail here.</p> <p>If there are tons of configuration options and you have some intelligent way of grouping them into categories, I'd build a higher level class that exposed (at least) two properties - a string <code>CategoryName</code> property and an <code>OptionsViews</code> collection - populate it from the XML document, and add it to the window's <code>ResourceDictionary</code>. Within the window, I'd bind it to a <code>TabControl</code>, e.g.:</p> <pre><code>&lt;TabControl ItemsSource="{DynamicResource OptionCategories}"&gt; &lt;TabControl.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type CategoryView}"&gt; &lt;Setter Property="Header" Value="{Binding Path=CategoryName}"/&gt; &lt;Setter Property="Content" Value="{Binding Path=OptionsViews}"/&gt; &lt;Setter Property="ContentTemplate" Value="{StaticResource OptionViewTemplate}"/&gt; &lt;/Style&gt; &lt;/TabControl.ItemContainerStyle&gt; &lt;/TabControl&gt; </code></pre> <p>Or to some item control whose item container template creates an <code>Expander</code>. Or something. (All code guaranteed untested! Most of it was copied out of working projects, though.)</p> <p>If you haven't done anything with WPF before, this is a pretty good project to start on. It'll expose you to the fundamentals of data binding and items controls and validation, and the end result will be something that's useful and probably looks pretty good. </p> <p>And you'll notice that while the markup involved in creating the templates is pretty verbose, there are only two templates. The only code in the application (so far) is the code that exposes the <code>XmlElement</code>s to the UI.</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.
    3. 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