Two questions about databinding. First of all I am trying to create a databinding to application settings. I have gone through about 10 tutorials and they all look like mine but its not working. First thing I did in BLEND 3 was add a textbox. Then I went into VISUAL STUDIO and added a user->setting named textboxText of type string. Then I went back over to BLEND and clicked on the button next to the text property and added a databinding to the textboxText and set it to TwoWay. Then in my Window Closing event I added "Properties.Settings.Default.Save();". However when I run the project again it has the same initial setting. Any ideas why? Here is my code generated by BLEND:
Code:<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication14_Properties="clr-namespace:WpfApplication14.Properties" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="WpfApplication14.MainWindow" x:Name="Window" Title="MainWindow" Width="640" Height="480" mc:Ignorable="d" Closing="Window_Closing"> <Window.Resources> <WpfApplication14_Properties:Settings x:Key="SettingsDataSource" d:IsDataSource="True"/> </Window.Resources> <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SettingsDataSource}}"> <TextBox HorizontalAlignment="Left" Margin="93,110,0,0" VerticalAlignment="Top" Width="120" Height="39" Text="{Binding textboxText, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextWrapping="Wrap"/> </Grid> </Window>
The other question that I have is can you databind to a variable or even a property. What I mean by that is say I set an integer value named myInteger to 5. Can I then display that in a textbox? If so an example or tutorial would be great.




Reply With Quote