0

I am just getting back into wpf a few years layoff and trying to remember some simple things.

I just created a test xaml file and I want to bind the the text of a label to a property but I don't remember the syntax. Here's what I tried:

<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>

and here is my Properties file:

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"]));
      }
    }
  }
}
Luke Willis
  • 8,429
  • 4
  • 46
  • 79
user565660
  • 1,171
  • 3
  • 20
  • 37

1 Answers1

1

Should be

<Label Content="{Binding Source={x:Static properties:Settings.Default}, Path=test}"/>
Luke Willis
  • 8,429
  • 4
  • 46
  • 79