How to implement interactive form modifications?

I'm trying to figure out how to save user modifications (i.e. personalizations) to a form. 

Consider a simple WPF input form, with two label/text boxes and two buttons, OK and Cancel.  The user wants to reorder the input boxes (or add/remove a column in a grid, reorder columns etc).  I was planning to modify the XAML dynamically (at the xml dom level) and save away the user's modified file.  Then when they reload it next time, everything is in their preferred layout.  Meanwhile, the buttons still work the way the original code behind requires.

Unfortunately, what I've read and tried so far says I can't do this without writing a complex property and event mapper to hook up the code behind, as what I really want to do would require me to recompile the xaml and partial class code behind file dynamically, so the events would get remapped at compile time.

Is this correct   I'll be happy to read any pointers you can give me to further investigate the technology details if I'm missing something.



Answer this question

How to implement interactive form modifications?

  • lucerias

    Mike, thanks for the pointer, but I don't think property persistence as described will be sophisticated enough.  If need be I can implement code to hook up event handlers etc myself, or look into dynamic compilation, I'd just prefer to avoid this.  Here is a specific example of the xaml file I would (possibly compile and) "ship" to a user.  If at that user site they add a new field to the database, ShoeSize, then I want to add an entry in the field rendering Grid to allow shoe size to be displayed if this user wants it. (The details of how the user discovers this, and how they add the field via the UI are a different topic!).

    At the end of the day I'd like to be able to dynamically load up either of the xaml files below, have the xaml data binding to a data source work (which it does), but also have the new file's events hook up just like the old one.  I'm looking for confirmation that this can only be done by recompiling, which appears to require the source (partial class file) and the new xaml to be in the same place at the same time, specifically at my customer site and not on my developer desktop!

    Original:

    <Page>
        <Grid>
            <TextBlock Grid.Column="0" Grid.Row="1" Name="lblFirstName">First Name</TextBlock>
            <TextBox Grid.Column="1" Grid.Row="1" Name="txtFirstName"/>
         
            <TextBlock Grid.Column="0" Grid.Row="2" Name="lblLastName">Last Name</TextBlock>
            <TextBox Grid.Column="1" Grid.Row="2" Name="txtLastName"/>
        </Grid>
        <Button Name="btnOK" Click="OKButtonClicked">OK</Button>
        <Button Name="btnCancel" Click="CancelButtonClicked">Cancel</Button>
    </Page>

    Modified:

    <Page>
        <Grid>
            <TextBlock Grid.Column="0" Grid.Row="1" Name="lblFirstName">First Name</TextBlock>
            <TextBox Grid.Column="1" Grid.Row="1" Name="txtFirstName"/>
          
            <TextBlock Grid.Column="0" Grid.Row="2" Name="lblLastName">Last Name</TextBlock>
            <TextBox Grid.Column="1" Grid.Row="2" Name="txtLastName"/>
         
            <TextBlock Grid.Column="0" Grid.Row="3" Name="lblShoeSize">Shoe Size</TextBlock>
            <TextBox Grid.Column="1" Grid.Row="3" Name="txtShoeSize"/>
        </Grid>
        <Button Name="btnOK" Click="OKButtonClicked">OK</Button>
        <Button Name="btnCancel" Click="CancelButtonClicked">Cancel</Button>
    </Page>

    So far I'm thinking I need a "mini aspx" -like engine on the client side, which is an interesting project but more work than I'd prefer to undertake!  Especially if I'm missing a feature in this brave, rich and complex new world.


  • AlanKohl

    You can use Application Settings to store the layout information for you. This article in the MSDN library will help you get started with how to do so. Your WPF app can bind to the App Settings and you can avoid having to find a way to persist this information yourself. Hopefully, "Cider" supports/will support binding to App settings within the designer like the winforms designer does currently.

  • How to implement interactive form modifications?