views:

303

answers:

2

Here is my layout:

<StackPanel>
    <!-- Defining my DDS here wont allow my ComboBox inside the DataTemplate bind to the loaded items -->
    <DomainDataSource x:Name="ddsValues" Query="MyQuery" DomainContext="{Binding DC}" />
    <DataForm>
        <DataForm.EditTemplate>
            <DataTemplate>
                <StackPanel>
                    <!-- Defining my DDS here works fine -->
                    <DomainDataSource x:Name="ddsValues" Query="MyQuery" DomainContext="{Binding DC}" />
                    <ComboBox ItemsSource="{Binding Data, ElementName=ddsValues}" />
                </StackPanel>
            </DataTemplate>
        </DataForm.EditTemplate>
    </DataForm>
</StackPanel>

Can anyone tell me why I have to setup my DomainDataSource this way? Why does it have to live inside the DataTemplate? Is there a way around this? Technically this means that EVERYTIME I change the record on the DataForm it has to RELOAD the values from the database. These values are static and wont change.

+2  A: 

Deborah Kurata's Silverlight and RIA: Adding a ComboBox to a DataForm post describes how to overcome this by using a Static Resource. I think Dan Wahlin's Creating a Silverlight DataContext Proxy to Simplify Data Binding in Nested Controls post describes the underlying issue in more detail.

Martin Hollingsworth
A: 

You have to set up your DDS like that because of the design limitations of SL1,2,3 detailed in the Dan Wahlin article already cited. In SL4 the underpinning problems are to a great extent resolved and a lot of this nonsense evaporates. In the meantime you either use Wahlin's solution or shrug and live with it, hoping things will improve in the next release (as they do).

Peter Wone