Ta Sas
Ta Sas

Reputation: 9803

Binding Properties.Settings to Textbox fails

I would like to define a key & value in Settings.settings and bind the value by declaration in the XAML (not in the code behind by command).

Here's what I've been trying in vain:

  1. Create a WPF project "Exp1" with Visual Studio Express 2010.
  2. Set one key named "TextFromSettings" to the value "Some Text from Setting".
  3. Add the attribute xmlns:p="clr-namespace:Exp1.Properties;assembly=Exp1" to the tag.
  4. Add Text="{Binding Path=TextFromSettings, Mode=TwoWay, Source={x:Static p:Settings.Default}}" to the tag

Now, the preview window shows the text, however, the compiler fails:

"Error 1 Cannot find the type 'Settings'. Note that type names are case sensitive."

Where am I going wrong?

enter image description here

Upvotes: 0

Views: 715

Answers (1)

brunnerh
brunnerh

Reputation: 184376

Drop the ;assembly=Exp1 it's not allowed for references to the current assembly.

If anything it should be ;assembly=, see MSDN.

assembly can be omitted if the clr-namespace referenced is being defined within the same assembly as the application code that is referencing the custom classes. Or, an equivalent syntax for this case is to specify assembly=, with no string token following the equals sign.

Upvotes: 1

Related Questions