Silverlight 4 combobox

G

Gerhard

I am posting this again at request of Microsoft concierge.

I have downloaded and installed both VS2010 RC and Silverlight 4 RC. In
testing out functionality, I built a simple RIA Business Application against
the Chinook database. I have a datagrid with the albums, another datagrid
with the tracks that ties to the selected album, and a combobox that ties to
the selected album's artist. When I do my first filter (using the built in
filter text box), all works fine, but if I change the filter, the combobox no
longer stays in sync (the datagrid does though). Can you please help? XAML
is as follows:

<navigation:page
x:Class="Chinook.Home"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
Style="{StaticResource PageStyle}"

xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:my="clr-namespace:Chinook.Web.Services"
xmlns:my1="clr-namespace:Chinook.Web.Models"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
DataContext="{Binding}">
<sdk:page.Resources>
<CollectionViewSource x:Key="albumTracksViewSource" Source="{Binding
Path=Data.Tracks, ElementName=albumDomainDataSource1}" />
</sdk:page.Resources>
<Grid x:Name="LayoutRoot">
<ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource
PageScrollViewerStyle}" Margin="-58,0,-58,-10">

<StackPanel x:Name="ContentStackPanel" Style="{StaticResource
ContentStackPanelStyle}">

<TextBlock x:Name="HeaderText" Style="{StaticResource
HeaderTextStyle}"
Text="{Binding
Path=ApplicationStrings.HomePageTitle, Source={StaticResource
ResourceWrapper}}"/>
<TextBlock x:Name="ContentText" Style="{StaticResource
ContentTextStyle}"
Text="Home page content"/>
<riaControls:DomainDataSource
AutoLoad="True"
d:DesignData="{d:DesignInstance my1:Artist,
CreateList=true}"
Height="0" LoadedData="artistDomainDataSource_LoadedData"
Name="artistDomainDataSource"
QueryName="GetArtistsQuery"
Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:ChinookContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<ComboBox Height="27"
Name="comboBox1"
Width="398"
ItemsSource="{Binding}"
DataContext="{Binding
ElementName=artistDomainDataSource, Path=Data}"
DisplayMemberPath="Name"
SelectedValuePath="ArtistId"
SelectedValue="{Binding ElementName=albumDataGrid,
Path=SelectedItem.ArtistId, Mode=TwoWay}" />
<riaControls:DomainDataSource
AutoLoad="False"
d:DesignData="{d:DesignInstance my1:Album,
CreateList=true}"
Height="0"
LoadedData="albumDomainDataSource_LoadedData"
Name="albumDomainDataSource"
QueryName="GetAlbumsByStartQuery"
Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:ChinookContext />
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaControls:parameter ParameterName="startString"
Value="{Binding ElementName=startStringTextBox, Path=Text}" />
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>
<StackPanel Height="30" Orientation="Horizontal">
<sdk:Label Content="Start String:" Margin="3"
VerticalAlignment="Center" />
<TextBox Name="startStringTextBox" Width="60" />
<Button Command="{Binding Path=LoadCommand,
ElementName=albumDomainDataSource}" Content="Load" Margin="3"
Name="albumDomainDataSourceLoadButton"
Click="albumDomainDataSourceLoadButton_Click" />
</StackPanel>
<sdk:DataGrid AutoGenerateColumns="False" Height="200"
ItemsSource="{Binding ElementName=albumDomainDataSource, Path=Data}"
Name="albumDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected"
Width="400">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="albumIdColumn"
Binding="{Binding Path=AlbumId}" Header="Album Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="artistIdColumn"
Binding="{Binding Path=ArtistId}" Header="Artist Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="titleColumn"
Binding="{Binding Path=Title}" Header="Title" Width="SizeToHeader" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<riaControls:DomainDataSource
AutoLoad="True"
d:DesignData="{d:DesignInstance my1:Track,
CreateList=true}"
Height="0"
LoadedData="trackDomainDataSource_LoadedData"
Name="trackDomainDataSource"
QueryName="GetTracksQuery"
Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:ChinookContext />
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.FilterDescriptors>
<riaControls:FilterDescriptor
PropertyPath="AlbumId"
Operator="IsEqualTo"
IgnoredValue=""
Value="{Binding ElementName=albumDataGrid,
Path=SelectedItem.AlbumId, Mode=TwoWay}" >
</riaControls:FilterDescriptor>
</riaControls:DomainDataSource.FilterDescriptors>
</riaControls:DomainDataSource>
<sdk:DataGrid AutoGenerateColumns="False" Height="200"
ItemsSource="{Binding ElementName=trackDomainDataSource, Path=Data}"
Name="trackDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected"
Width="400">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="albumIdColumn1"
Binding="{Binding Path=AlbumId}" Header="Album Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="bytesColumn"
Binding="{Binding Path=Bytes}" Header="Bytes" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="composerColumn"
Binding="{Binding Path=Composer}" Header="Composer" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="genreIdColumn"
Binding="{Binding Path=GenreId}" Header="Genre Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="mediaTypeIdColumn"
Binding="{Binding Path=MediaTypeId}" Header="Media Type Id"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="millisecondsColumn"
Binding="{Binding Path=Milliseconds}" Header="Milliseconds"
Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="nameColumn"
Binding="{Binding Path=Name}" Header="Name" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="trackIdColumn"
Binding="{Binding Path=TrackId}" Header="Track Id" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="unitPriceColumn"
Binding="{Binding Path=UnitPrice}" Header="Unit Price" Width="SizeToHeader" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</StackPanel>

</ScrollViewer>
</Grid>

</navigation:page>
 
A

Allen Chen-MSFT

Hi Gerhard,

Could you please send me your project for me to reproduce this issue?
(including DB file, remove sensitive information) Please send the project to
allenc at microsoft.com and keep the project as simple as possible.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues where
an initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent, real-time
or phone-based interactions. Issues of this nature are best handled working
with a dedicated Microsoft Support Engineer by contacting Microsoft Customer
Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Gerhard

Thanks, I have emailed you a simplified version of the project with just the
combo box added.
 
G

Gerhard

Hi,

Did you receive the solution file I sent to you?

Were you able to duplicate the issue?

Thanks.

Have a happy day!
 
A

Allen Chen [MSFT]

Hi Gerhard,
Did you receive the solution file I sent to you?
Were you able to duplicate the issue?

Have a happy day!

Yes thanks for the project. I could reproduce this issue and had worked for
several hours to get it finally working.

As to the scrolling issue, this is a known issue that if the items in
ComboBox have different width we cannot scroll

up or down properly.

Workaround is to give the VirtualizingStackPanel or StackPanel a fixed
width. I don't recommend you use

VirtualizingStackPanel currently in ComboBox because there're other known
issues regarding VirtualizingStackPanel

+ComboBox:


<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Width="300" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>

To avoid potential CanLoad issue of DomainDataSource, please add the
following code to your TextBox:

<TextBox IsEnabled="{Binding
ElementName=albumDomainDataSource, Path=CanLoad}" Name="startStringTextBox"
Width="60" />

And add the following event handler for ComboBox. (I found somehow the
second binding breaks the two way binding of ComboBox so I manually "bind"
data in this event handler to work around)

private void artistComboBox_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
var album=albumDataGrid.SelectedItem as Album;
if (album != null)
{
album.ArtistId =
((Artist)artistComboBox.SelectedItem).ArtistId;
}
albumDomainDataSource.SubmitChanges();
}

<ComboBox Height="23"
ItemsSource="{Binding
ElementName=artistDomainDataSource, Path=Data}"
DisplayMemberPath="Name"
SelectionChanged="artistComboBox_SelectionChanged"
SelectedValuePath="ArtistId"
SelectedValue="{Binding
ElementName=albumDataGrid, Path=SelectedItem.ArtistId, Mode=TwoWay}"
Name="artistComboBox"
Width="120">
....

After all above steps your project works fine at my side. Please test and
let me know whether it works for you. If you have additional questions
please feel free to ask. I'll do my best to follow up.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
G

Gerhard

Thanks for all your work.

The scroll part it working fine.

However, I still don't see that the binding between the two is working.
When I put 'ba' into the start string, all is working fine. When I change
the 'ba' to 'bach' and load, the combobox does not select the correct artist.

Also, if I take out the submitchanges from the code behind, the start string
and load button stay disabled. I'm not always going to want a save to be
automatic on any change in a combo box selection.

Are the development folks working to get the combo box working as expected
before they release the product?

One other question, how do I get the Load button to fire when hit enter
after putting in a start string?

Thanks again for all you work on this.
 
A

Allen Chen [MSFT]

Hi Gerhard,
However, I still don't see that the binding between the two is working.
When I put 'ba' into the start string, all is working fine. When I change
the 'ba' to 'bach' and load, the combobox does not select the correct
artist.

It looks like a known issue of ComboBox databinding. You probably have to
manually bind to workaround. i.e. In albumDataGrid_SelectionChanged and
artistComboBox_SelectionChanged manually sync the DataGrid and ComboBox.
Also, if I take out the submitchanges from the code behind, the start string
and load button stay disabled. I'm not always going to want a save to be
automatic on any change in a combo box selection.

The cause of this behavior is, the DomainDataSource keeps tracking changes
of data it retrieved. If data is changed it doesn't allow load operation
before submitting changes. To workaround this issue you can use cached data
source instead of using Data of DomainDataSource.

First please refer ItemsSource definition of albumDomainDataSource in xaml.
Then use following code instead:

private void albumDomainDataSource_LoadedData(object sender,
LoadedDataEventArgs e)
{

if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load
Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
else {
DomainDataSourceView ddsv=
(DomainDataSourceView)albumDomainDataSource.Data;
List<Album> list = new List<Album>();// You may use global
variable instead to cache data source.
foreach (Album album in ddsv)
{
// use cached data instead to avoid tracking changes of
original data
Album cacheddata = new Album() { Artist = album.Artist,
ArtistId = album.ArtistId };
list.Add(cacheddata);
}
this.albumDataGrid.ItemsSource = list;
}

}

When you want to save changes you can manually assign cached data to Data
of DomainDataSource and submit changes.
Are the development folks working to get the combo box working as expected
before they release the product?

Our product team is working on it. But as far as I can tell unfortunately
some of the known issues of CombBox are not likely to be fixed in SL 4 RTW
(we'll do our best, however, to fix as much as possible before RTW). We
will address these issues in SL 5. If you have any problems in CombBox
please let me know. I think we can find workarounds for most of these known
issues.
One other question, how do I get the Load button to fire when hit enter
after putting in a start string?

You can refer to the following blog:
http://azurecoding.net/blogs/icbtw/archive/2009/09/02/xaml-default-button.as
px

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
G

Gerhard

Thanks for your feedback. I was hoping that SL4 would fix the combo box (I
have work arounds that are working in SL3) so it would be cleaner and easier
to maintain. Please let me know if it does get fixed.

Have a happy day!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top