So I wrote my multi threaded app to test another app and it works! :)
Funny thing is I was spending an couple of hours trying to track down a bug, and found I had mistyped a method so it was pointing to the wrong method.
I guess I've learned to keep my method names looking very different from eachother instead of method1 and method2.
Thursday, April 29, 2010
Friday, April 23, 2010
WPF Binding Control, It works!
Well I am a little dense but I finally figured it out. Used this article:
Now when I select a server from my drop down list it populates the correct text box using binding. :) !
<StackPanel DataContext="{Binding}" Width="444" Height="341">
<StackPanel.Resources>
<!-- Instantiate the object ServerControls and call the method GetServerList, This goes out and builds a list of Server Objects
that have the server name, ip, and port-->
<ObjectDataProvider x:Key="servers"
ObjectType="{x:Type svc:ServersControl}"
MethodName="GetServerList"></ObjectDataProvider>
<!-- Format how each server object will be displayed. Name in bold and blue, IP and port below seperated with a colon-->
<DataTemplate x:Key="serverLayout" DataType="Server">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="Blue"></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Ip}"></TextBlock>
<TextBlock Text=":"> </TextBlock>
<TextBlock Text="{Binding Path=Port}"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</StackPanel.Resources>
<!-- Create my ListBox and bind it to the resources I created above.-->
<ListBox Height="200" Name="listBox1" Width="Auto" ItemsSource="{Binding Source={StaticResource servers}}"
ItemTemplate="{DynamicResource serverLayout}"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding SelectedItem}"
>
</ListBox>
<Label Content="Select a server from the list or manually input below." Height="27" Name="label1" Width="286" />
<!--I had to include a data context for the grid I was putting my text boxes in-->
<Grid Width="Auto" Height="Auto" Background="AliceBlue" DataContext="{Binding ElementName=listBox1, Path=SelectedItem}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Margin="5" Text="IP:" Grid.Column="0" FlowDirection="LeftToRight"></TextBlock>
<TextBox Margin="5" Grid.Column="1" Name="TextBoxIP" Text="{Binding Path=Ip}" />
<TextBlock Margin="5" Text="Port:" Grid.Column="2"></TextBlock>
<TextBox Margin="5" Grid.Column="3" Name="TextBoxPort" Text="{Binding Path=Port}"></TextBox>
<TextBlock Margin="5" Text="UserName:" Grid.Column="0" FlowDirection="LeftToRight" Grid.Row="2"></TextBlock>
<TextBox Text="Administrator" Name="TextBoxUsername" Margin="5" Grid.Column="1" Grid.Row="2"></TextBox>
<TextBlock Margin="5" Text="Password:" Grid.Column="2" Grid.Row="2"></TextBlock>
<PasswordBox Name="TextBoxPwd" Margin="5" Grid.Column="3" Grid.Row="2" ></PasswordBox>
</Grid>
<StackPanel DataContext="{Binding}" Width="444" Height="341">
<StackPanel.Resources>
<!-- Instantiate the object ServerControls and call the method GetServerList, This goes out and builds a list of Server Objects
that have the server name, ip, and port-->
<ObjectDataProvider x:Key="servers"
ObjectType="{x:Type svc:ServersControl}"
MethodName="GetServerList"></ObjectDataProvider>
<!-- Format how each server object will be displayed. Name in bold and blue, IP and port below seperated with a colon-->
<DataTemplate x:Key="serverLayout" DataType="Server">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="Blue"></TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Ip}"></TextBlock>
<TextBlock Text=":"> </TextBlock>
<TextBlock Text="{Binding Path=Port}"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</StackPanel.Resources>
<!-- Create my ListBox and bind it to the resources I created above.-->
<ListBox Height="200" Name="listBox1" Width="Auto" ItemsSource="{Binding Source={StaticResource servers}}"
ItemTemplate="{DynamicResource serverLayout}"
IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding SelectedItem}"
>
</ListBox>
<Label Content="Select a server from the list or manually input below." Height="27" Name="label1" Width="286" />
<!--I had to include a data context for the grid I was putting my text boxes in-->
<Grid Width="Auto" Height="Auto" Background="AliceBlue" DataContext="{Binding ElementName=listBox1, Path=SelectedItem}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Margin="5" Text="IP:" Grid.Column="0" FlowDirection="LeftToRight"></TextBlock>
<TextBox Margin="5" Grid.Column="1" Name="TextBoxIP" Text="{Binding Path=Ip}" />
<TextBlock Margin="5" Text="Port:" Grid.Column="2"></TextBlock>
<TextBox Margin="5" Grid.Column="3" Name="TextBoxPort" Text="{Binding Path=Port}"></TextBox>
<TextBlock Margin="5" Text="UserName:" Grid.Column="0" FlowDirection="LeftToRight" Grid.Row="2"></TextBlock>
<TextBox Text="Administrator" Name="TextBoxUsername" Margin="5" Grid.Column="1" Grid.Row="2"></TextBox>
<TextBlock Margin="5" Text="Password:" Grid.Column="2" Grid.Row="2"></TextBlock>
<PasswordBox Name="TextBoxPwd" Margin="5" Grid.Column="3" Grid.Row="2" ></PasswordBox>
</Grid>
Data Binding in WPF
Found some great articles about WPF out there this week.
This guys has a great series:
http://www.codeproject.com/KB/WPF/GuidedTourWPF_1.aspx
And I used this website as well:
http://www.codeproject.com/KB/WPF/winforms2wpf.aspx
Data binding is really handy for the UI.
I populated a listbox using an xaml command to create an object, called a method that created a list of objects and then automagically populated the list box.
Now how to get that data out of my list box and into my connection string.
[edit] Found a stack overflow link that might help
http://stackoverflow.com/questions/2012460/wpf-binding-to-listbox-selecteditem
This guys has a great series:
http://www.codeproject.com/KB/WPF/GuidedTourWPF_1.aspx
And I used this website as well:
http://www.codeproject.com/KB/WPF/winforms2wpf.aspx
Data binding is really handy for the UI.
I populated a listbox using an xaml command to create an object, called a method that created a list of objects and then automagically populated the list box.
Now how to get that data out of my list box and into my connection string.
[edit] Found a stack overflow link that might help
http://stackoverflow.com/questions/2012460/wpf-binding-to-listbox-selecteditem
Subscribe to:
Posts (Atom)