Click here to Skip to main content
11,572,251 members (72,931 online)
Click here to Skip to main content
Add your own
alternative version

WPF Persistency

, 3 Jan 2013 CPOL 51.8K 577 58
This article describes how to persist WPF dependency properties
<Window x:Class="WpfPersist.Demo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:app="clr-namespace:WpfPersist"
        Title="WpfPersist.Demo"
        Height="{app:UserSettings Default=300}" Width="{app:UserSettings Default=400}"
        Top="{app:UserSettings}" Left="{app:UserSettings}"
        >
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="{app:UserSettings Default=100}" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>

        <StackPanel Grid.Column="0" Grid.Row="0" Background="AliceBlue">
            <GroupBox Margin="4" Header="TextBox">
                <TextBox Margin="4" Text="{app:UserSettings default text}" />
            </GroupBox>
            <GroupBox Margin="4" Header="CheckBox">
                <StackPanel>
                    <CheckBox Margin="4" IsChecked="{app:UserSettings}">Check1</CheckBox>
                    <CheckBox Margin="4" IsChecked="{app:UserSettings}">Check2</CheckBox>
                </StackPanel>
            </GroupBox>
            <GroupBox Margin="4" Header="RadioButton">
                <StackPanel>
                    <RadioButton Margin="4" IsChecked="{app:UserSettings Default='True'}">Radio1</RadioButton>
                    <RadioButton Margin="4" IsChecked="{app:UserSettings Default='False'}">Radio2</RadioButton>
                </StackPanel>
            </GroupBox>
        </StackPanel>

        <GridSplitter ResizeBehavior="CurrentAndNext" Width="2" ResizeDirection="Columns" VerticalAlignment="Stretch" HorizontalContentAlignment="Right" />

        <DockPanel Grid.Column="1" Grid.Row="0" >
            <TextBox Margin="4" DockPanel.Dock="Bottom" Name="tbLocalPath" IsReadOnly="True" Text="{Binding Path='ExeLocalConfigPath', Mode='OneTime'}" />
            <ListView Name="lvProcesses">
                <ListView.View>
                    <GridView >
                        <GridViewColumn
                          DisplayMemberBinding="{Binding Mode=OneTime,Path=ProcessName}"
                          Header="ProcessName"
                          Width="{app:UserSettings Default=100, Key=Window1.ListView0.Col0.Width }" />
                        <GridViewColumn
                          DisplayMemberBinding="{Binding Mode=OneTime,Path=Id}"
                          Header="Id"
                          Width="{app:UserSettings Default=100, Key=Window1.ListView0.Col1.Width}" />
                        <GridViewColumn
                          DisplayMemberBinding="{Binding Mode=OneTime,Path=MainWindowTitle}"
                          Header="MainWindowTitle"
                          Width="{app:UserSettings Default=Auto, Key=Window1.ListView0.Col2.Width}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Reto Ravasio
Switzerland Switzerland
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 3 Jan 2013
Article Copyright 2007 by Reto Ravasio
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid