如何将xaml按钮绑定到属性

时间:2013-08-22 19:50:09

标签: wpf

我刚刚回到wpf几年裁员并试图记住一些简单的事情。

我刚刚创建了一个测试xaml文件,我想将标签的文本绑定到属性,但我不记得语法。这是我试过的:

<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="5" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
      <RowDefinition Height="11" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition Width="200" />
    </Grid.ColumnDefinitions>

    <Label Grid.Row="0" Grid.Column="0" Content="{Binding WpfApplication1.Properties.test}"/>
    <Label Grid.Row="1" Grid.Column="0" Content="E-Mail:"/>
    <Label Grid.Row="2" Grid.Column="0" Content="Comment:"/>

  </Grid>       
</Window>

这是我的属性文件:

namespace WpfApplication1.Properties {


[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

    private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

    public static Settings Default {
      get {
        return defaultInstance;
      }
    }

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("doug")]
    public string test {
      get {
        return ((string)(this["test"]));
      }
    }
  }
}

1 个答案:

答案 0 :(得分:2)

应该是

<Label Content="{Binding Source={x:Static properties:Settings.Default}, Path=test}"/>