开发者

Silverlight WCF RIA : How to use comboboxes in DataForms

I have spent nearly few hours on this issue and I am pulling my hair... My code follows:

        <toolkit:DataForm MaxWidth="400" Name="dataForm_EditWBS" Header="WBS Task"  AutoCommit="True" AutoEdit="True" AutoGeneratingField="dataForm_EditWBS_AutoGeneratingField">
      <toolkit:DataForm.EditTemplate>
            <DataTemplate>
                <StackPanel>
                    <toolkit:DataField Label="Phase">


                            <ComboBox x:Name="ComboBoxEdit_Phase" DisplayMemberPath="PhaseDescription" SelectedValuePath="PhaseID" 
                                      SelectedItem="{Binding PhaseID, Mode=TwoWay}" 
                                      />

                        </toolkit:DataField>
                    <toolkit:DataField Label="Task">
                        <TextBox 
                                     Text="{Binding TaskDescription, Mode=TwoWay}"/>
                    </toolkit:DataField>
                    <toolkit:DataField Label="Comments">
                        <TextBox HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" Height="60" TextWrapping="Wrap"
                                     Text="{Binding TaskComments, Mode=TwoWay}"/>
                    </toolkit:DataField>
                    <toolkit:DataField Label="Resource Type">
                        <ComboBox x:Name="cbResourceType"
                                  SelectedItem="{Binding PhaseID, Mode=TwoWay}" DisplayMemberPath="PhaseDescription" SelectedValue="PhaseID" />

                    </t开发者_运维技巧oolkit:DataField>
                    <toolkit:DataField Label="Resource">
                        <ComboBox x:Name="cbResource"
                                  SelectedItem="{Binding PhaseID, Mode=TwoWay}" DisplayMemberPath="PhaseDescription" SelectedValue="PhaseID" />

                    </toolkit:DataField>
                    <toolkit:DataField Label="Hours">
                        <TextBox
                                     Text="{Binding Hours, Mode=TwoWay, StringFormat='n'}"/>
                    </toolkit:DataField>
                    <toolkit:DataField Label="Cost">
                        <TextBox
                                     Text="{Binding Hours, Mode=TwoWay, StringFormat='c'}"/>
                    </toolkit:DataField>
                </StackPanel>
            </DataTemplate>
        </toolkit:DataForm.EditTemplate>
    </toolkit:DataForm>
   </StackPanel>

The source for my comboboxes comes from another table, anyone know how I can populate this with items. Really appreciate it!

Thanks,

Nicholas


Create a class that models the data that the form needs for all its data binding (including the comboboxes) and databind the ItemsSource of the comboboxes to the collection of items they need to display (present as a property on the new class). Then set the DataContext of the form to an instance of this new class.

Generally this new class is called a ViewModel and this is one aspect of the Model / View / ViewModel design pattern (MVVM)


Following on from Richards answer check out Microsoft's Unity and Caliburn.Micro to get started with MVVM. I tried to implement MVVM myselfand it was a horrid affair. The libraries I have mentioned make it much easier to understand MVVM and how to implement it.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜