Click here to Skip to main content
15,897,371 members
Articles / Desktop Programming / WPF

WPF Persistency

Rate me:
Please Sign up or sign in to vote.
4.84/5 (19 votes)
3 Jan 2013CPOL2 min read 93.9K   784   60  
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)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions