WPF窗口位置绑定

Max*_*ich 4 c# wpf settings binding

在Windows窗体中,窗体的属性部分中有一个选项,用于在应用程序设置和窗体窗体之间建立绑定.

通常,我会最终有一个叫frmMyFormName_Location这是必需的,然后自动地更新设置和所有我需要做的是调用应用程序退出的Settings.Save()方法,保留位置.

有人可以在WPF中提供相同的例子,因为我一直无法弄清楚如何实现这一目标吗?

mad*_*dd0 20

.settingsWPF中的文件绑定到用户或应用程序设置非常简单.

这是一个窗口的示例,它从设置中获取其位置和大小:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:settings="clr-namespace:WpfApplication1.Properties"
        Height="{Binding Height, Source={x:Static settings:Settings.Default}, Mode=TwoWay}" 
        Width="{Binding Width, Source={x:Static settings:Settings.Default}, Mode=TwoWay}"
        Top="{Binding Top, Source={x:Static settings:Settings.Default}, Mode=TwoWay}"
        Left="{Binding Left, Source={x:Static settings:Settings.Default}, Mode=TwoWay}">
    <Grid>

    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

设置如下所示:

设置文件

并坚持下去,我只是使用以下代码:

void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    Properties.Settings.Default.Save();
}
Run Code Online (Sandbox Code Playgroud)