Hi everyone,
I am trying to create a simple WPF form that consists of a combo-box that is used to select a value (a Guid) that represents the parm for a CslaDataProvider (which is the DataSource of a ListBox).
I can make it work fine if I hook the SelectionChanged event of the combo-box and explicitly set the CslaDataProvider parm with the SelectedValue.
But if I try to use databinding to automatically update the parm from the SelectedValue of the combo-box, I get curious results.
1) SelectedValue in the combo-box never gets (completely) set during InitializeComponent. SelectionChanged is raised TWO times for the combo-box. The first time, the SelectedItem is correct, but SelectedValue is Nothing (null). The second time it's raised there is NO selected item (SelectedIndex = -1) and both SelectedItem and SelectedValue are Nothing. Without the databinding, I get the expected behavior. SelectedIndex is set to 0 (as specificed in the Xaml), SelectedItem and SelectedValue are both correct.
2) The list of the Combo-box is populated, and I can select an entry. That entry correctly updates the value of my CslaDataProvider parm. But the CslaDataProvider never re-queries on this change. The only way I can get it to update is to set the parm value in code.
Here's the Xaml (edited to shorten it) with the Databinding code...
<
Window x:Class="DesFamilyEditForm" xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
Title="Edit Descriptor Families" Height="370" Width="300" Name="DesFamilyEditForm" FlowDirection="LeftToRight"
Loaded ="OnLoadedHandler">
<Window.Resources>
<csla:CslaDataProvider x:Key="FamiliesList"
ObjectType="{x:Type lib:DFamiliesList}"
FactoryMethod="GetEditableRootList"
ManageObjectLifetime="True"
IsInitialLoadEnabled="False">
<csla:CslaDataProvider.FactoryParameters>
<ms:Guid>00000000-0000-0000-0000-000000000000</ms:Guid>
</csla:CslaDataProvider.FactoryParameters>
</csla:CslaDataProvider>
<csla:CslaDataProvider x:Key="FamTypesList"
ObjectType="{x:Type lib2:DFTypesListInfo}"
FactoryMethod="GetList"
ManageObjectLifetime="False">
</csla:CslaDataProvider>
</Window.Resources>
<Grid Name="mainGrid" FlowDirection="LeftToRight">
<Grid.RowDefinitions>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Name="FamTypeSelector" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Margin="10,5,2,0" Name="TypeLabel" Text="Family Type : " IsEnabled="False" VerticalAlignment="Center"
FontStyle="Normal" TextDecorations="None" FontWeight="Bold"/>
<ComboBox Margin="10,5,2,0" Name="FamTypeCB" MinWidth="175"
Height="25" IsEnabled="True" FontStyle="Normal"
FontWeight="Bold" IsEditable="False" IsReadOnly="True" SelectedValuePath="Id" SelectedIndex="0"
ItemsSource="{Binding Source ={StaticResource FamTypesList}}" SelectionChanged="FamTypeCB_SelectionChanged">
<ComboBox.SelectedValue>
<Binding Source="{StaticResource FamiliesList}"
Path="FactoryParameters[0]"
BindsDirectlyToSource="True"
Mode="OneWayToSource"
UpdateSourceTrigger="PropertyChanged">
</Binding>
</ComboBox.SelectedValue>
</ComboBox>
</StackPanel>
<ListBox Name="FamilyTable" Grid.Row="2" Margin="10,0,2,0" ItemsSource="{Binding Source ={StaticResource FamiliesList}}"
KeyboardNavigation.TabNavigation="Continue" Loaded="FamilyTable_Loaded" IsSynchronizedWithCurrentItem="True">
<ListBox.ItemTemplate>
<!-- Format stuff here -->
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</
Window>
Any suggestions? (BTW my code behind is in VB, and I know it looks strange to use FactoryParamters[0] as the Binding source for SelectedValue, but the parm doesn't update otherwise).
Thanks.
BBM