Silverlight系统,其中asp用户药房有一个链接表供他们使用。我试图在列表(datagrid)中显示此库存,并为他们提供一种通过数据网格编辑和添加项目到列表的方法。目前我正在努力解决这个数据形式的绑定...... Xaml提供了什么帮助?
<Grid x:Name="LayoutRoot">
<Button Content="Save Changes" Height="52" Width="103" Name="SaveChangesButton" VerticalAlignment="Top" Click="SaveChanges" ContentTemplate="{Binding}" Margin="169,309,367,0" />
<Button Content="Discard Changes" Height="52" Width="103" Name="DiscardChangesButton" VerticalAlignment="Top" Click="DiscardChanges" ContentTemplate="{Binding}" Margin="288,309,250,0" />
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:User_Pharmacy, CreateList=true}" Height="0" LoadedData="user_PharmacyDomainDataSource_LoadedData_1" Name="user_PharmacyDomainDataSource" QueryName="GetUser_PharmacyMedInvASPQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my1:MediNetDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<sdk:DataGrid AutoGenerateColumns="False" Height="406" HorizontalAlignment="Left" ItemsSource="{Binding ElementName=user_PharmacyDomainDataSource, Path=Data}" Margin="12,37,0,0" Name="medicineInventoryDataGrid" VerticalAlignment="Top" Width="107" >
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn x:Name="medName" Binding="{Binding Path=MedicineName}" Header="Medicine Name" Width="SizeToHeader" Visibility="Visible" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="336,420,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" />
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:User_Pharmacy, CreateList=true}" Height="0" LoadedData="user_PharmacyDomainDataSource1_LoadedData" Name="user_PharmacyDomainDataSource1" QueryName="GetUser_PharmacyASPQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my1:MediNetDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<toolkit:DataForm HorizontalAlignment="Left" Margin="151,37,0,0" Name="dataForm1" VerticalAlignment="Top" Width="258" Height="223" ItemsSource="{Binding ElementName=user_PharmacyDomainDataSource, Path=Data.}" CommandButtonsVisibility="All">
<toolkit:DataForm.ReadOnlyTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<sdk:Label Content="Medicine Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="medicineNameTextBox" Text="{Binding Path=MedicineName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="True"/>
<sdk:Label Content="Price:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="3" Name="priceTextBox" Text="{Binding Path=Price, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="True"/>
<sdk:Label Content="Quantity:" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="3" Name="quantityTextBox" Text="{Binding Path=Quantity, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="True" />
</Grid>
</DataTemplate>
</toolkit:DataForm.ReadOnlyTemplate>
<toolkit:DataForm.NewItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<sdk:Label Content="Medicine Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="medicineNameTextBox" Text="{Binding Path=MedicineName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False"/>
<sdk:Label Content="Price:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="3" Name="priceTextBox" Text="{Binding Path=Price, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False"/>
<sdk:Label Content="Quantity:" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="3" Name="quantityTextBox" Text="{Binding Path=Quantity, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False" />
</Grid>
</DataTemplate>
</toolkit:DataForm.NewItemTemplate>
<toolkit:DataForm.EditTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<sdk:Label Content="Medicine Name:" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="3" Name="medicineNameTextBox" Text="{Binding Path=MedicineName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False"/>
<sdk:Label Content="Price:" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" HorizontalAlignment="Left" Margin="3" Name="priceTextBox" Text="{Binding Path=Price, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False"/>
<sdk:Label Content="Quantity:" Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Margin="3" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="3" Name="quantityTextBox" Text="{Binding Path=Quantity, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" VerticalAlignment="Center" Width="120" IsReadOnly="False" />
</Grid>
</DataTemplate>
</toolkit:DataForm.EditTemplate>
</toolkit:DataForm>
</Grid>
答案 0 :(得分:0)
使用两组文本块创建我自己的自定义版本,一组用于编辑/添加,只有可见,另一组用于查看。如果有人有兴趣,我可以分享代码。