Question How to use the databinding in WPF using Resourse Settings Variables Saving?

AukI

Member
Joined
Nov 20, 2010
Messages
17
Programming Experience
3-5
I can see that there are binding options but i can't set them as windows forms application ...

f2q7n7.png


I use windows forms applications textbox to bind with a settings variable to save data but in wpf , i can't find a way to do that.

2f0a89f.png


can anyone give some screen shots how to make it work..


thanks in advance..
 
You need to first import your project's default namespace into your XAML file. If you go to the Window tag at the top of the XAML code, you'll notice a couple of namespace imports using the 'xmlns' attribute. The first one is the default namespace for the file and the second uses the alias 'x'.

Under the last existing import, type:
VB.NET:
xmlns:project=""
After you type the '=', the double quotes should be added automatically and Intellisense should show you a list of available namespaces. Scroll down that list until you find the default namespace for your project and select it. That's the namespace imported, so you can now use its members in your XAML code.

To bind to a property of My.Settings in XAML, you can now do something like this:
VB.NET:
<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    [B][U]xmlns:project="clr-namespace:WpfApplication1"[/U][/B]
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120"
                 [B][U]Text="{Binding Source={x:Static project:MySettings.Default}, Path=SomeStringSetting}"[/U][/B]/>
    </Grid>
</Window>
The MySettings.Default leads to the same object as My.Settings in procedural code. You assign your setting property to the Path attribute.
 
Back
Top