Monday, July 18, 2011

WPF-Combo Box Binding example

Following sample will show how to databind in WPF ComboBox

Following code goes into your xaml file

----------------------------------------------------------------------------------------
<ComboBox Name="comboBox1" Grid.Row="1" Grid.Column="2" SelectionChanged="comboBox1_DropDownClosed"
DataContext="Binding ElemntName=LanguageListBinding,Path=SelectedItem" FontSize="13" Height="20" >

<ComboBox.ItemTemplate>

<DataTemplate>

<StackPanel Name="spSitePanel" Orientation="Horizontal">
<TextBlock Visibility="Hidden" Width="0" x:Name="txtSiteID" Text="{Binding Path=LanguageID}" />
<TextBlock x:Name="txtSiteName" Text="{Binding Path=Language}" />



</StackPanel>

</DataTemplate>

</ComboBox.ItemTemplate>
</ComboBox>
---------------------------------------------------------------------------------------------------------

following code goes into codebehind of xaml file (cs file)

public static localhost1.MyClass g_ProxyWebService;
g_ProxyWebService = new localhost1.MyClass();

... ......... .......... ...........

... ......... .......... ...........
Binding LanguageListBinding = new Binding();localhost1.clsUser[] objProtocol = g_ProxyWebService.GetLanguageList();
LanguageListBinding.Source = objProtocol;

comboBox1.SetBinding(ComboBox.ItemsSourceProperty, LanguageListBinding);
comboBox1.SelectedIndex = 0;



----------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Open default email app in .NET MAUI

Sample Code:  if (Email.Default.IsComposeSupported) {     string subject = "Hello!";     string body = "Excellent!";    ...