SilverLight合计行设计
这几天在网上找了很多关于SilverLight合计行的处理办法
最好敲定了。。。图片如下:
看到上面的合计行 实在有点心动啊。。。
xaml代码:
View Code
<Grid Grid.Row="1" >
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="410*"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="14" Margin="5" Grid.Row="0">总账明细:</TextBlock>
<data:DataGrid x:Name="gridList" Grid.Row="1" Margin="5,0,5,0" GridLinesVisibility="All" AutoGenerateColumns="False" FrozenColumnCount="1" AreRowDetailsFrozen="True" HorizontalAlignment="Stretch" CanUserSortColumns="False" ItemsSource="{Binding InvStockListModelList,Mode=TwoWay}" IsReadOnly="True" SelectedItem="{Binding InvStockListModel,Mode=TwoWay}">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="物料名称" Binding="{Binding MaterialModel.Mat_Name,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="仓库名称" Binding="{Binding StorgeModel.Storge_Name,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="库位名称" Binding="{Binding InvLocationModel.Location_Name,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="批号" Binding="{Binding StockList_Batch,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="年度" Binding="{Binding StockList_Year,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="会计期间" Binding="{Binding StockList_Period,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="收入数量" Binding="{Binding StockList_IAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="收入单价" Binding="{Binding StockList_IPrice,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="收入金额" Binding="{Binding StockList_IMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="发出数量" Binding="{Binding StockList_OAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="发出单价" Binding="{Binding StockList_OPrice,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="发出金额" Binding="{Binding StockList_OMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="期末数量" Binding="{Binding StockList_EndAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="期末金额" Binding="{Binding StockList_EndMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="供应商批号" Binding="{Binding StockList_SuppBatch,Mode=TwoWay}"/>
</data:DataGrid.Columns>
</data:DataGrid>
<Border Grid.Row="2" BorderThickness="1,0,1,1" BorderBrush="#6c7175" Margin="5,0,5,0" >
<Grid x:Name="gridFooterList" HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Top" Margin="5,0,5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<sdk:Label Content="合 计:" FontSize="13" />
<sdk:Label Grid.Column="6" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_IAmount" />
<sdk:Label Grid.Column="8" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_IMoney" />
<sdk:Label Grid.Column="9" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_OAmount" />
<sdk:Label Grid.Column="11" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_OMoney" />
<sdk:Label Grid.Column="12" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_EndAmount" />
<sdk:Label Grid.Column="13" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockList_EndMoney" />
</Grid>
</Border>
</Grid>
cs代码:
使datagrid列的宽带改变后,合计行也对应改变
注意:合计行设计的Grid的列数要和datagrid的列数相等
View Code
public InvStockListView()
{
InitializeComponent();
gridList.LayoutUpdated += new EventHandler(gridList_LayoutUpdated);
}
void gridList_LayoutUpdated(object sender, EventArgs e)
{
SyncColumnWidths(gridList, gridFooterList);
}
static void SyncColumnWidths(DataGrid source, Grid target)
{
if (source == null || target == null)
{
return;
}
if (target.ColumnDefinitions.Count != source.Columns.Count) return;
for (int i = 0; i < target.ColumnDefinitions.Count; i++)
{
target.ColumnDefinitions[i].Width = new GridLength(source.Columns[i].ActualWidth);
}
}
合计行代码:
View Code
/// <summary>
/// 库存明细合计行计算
/// </summary>
public void GetStockListSum()
{
decimal StockList_IAmount = 0, StockList_IMoney = 0,
StockList_OAmount = 0, StockList_OMoney = 0,
StockList_EndAmount = 0, StockList_EndMoney = 0;
foreach (var model in InvStockListModelList)
{
StockList_IAmount += model.StockList_IAmount;
StockList_IMoney += model.StockList_IMoney;
StockList_OAmount += model.StockList_OAmount;
StockList_OMoney += model.StockList_OMoney;
StockList_EndAmount += model.StockList_EndAmount;
StockList_EndMoney += model.StockList_EndMoney;
}
lblStockList_IAmount.Content = StockList_IAmount;
lblStockList_IMoney.Content = StockList_IMoney.ToString("C");
lblStockList_OAmount.Content = StockList_OAmount;
lblStockList_OMoney.Content = StockList_OMoney.ToString("C");
lblStockList_EndAmount.Content = StockList_EndAmount;
lblStockList_EndMoney.Content = StockList_EndMoney.ToString("C");
}
大功告成!!!