SilverLight触发器加Command命令实现双击行弹出窗体
效果预览:
截图有点大。。。别介意哦。。。
言归正传:
xaml代码:
View Code
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="270*"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="14" Margin="5" Grid.Row="0">库存总账条目:</TextBlock>
<data:DataGrid x:Name="dglist" Grid.Row="1" Margin="5,0,5,0" GridLinesVisibility="All"
AutoGenerateColumns="False"
FrozenColumnCount="1"
AreRowDetailsFrozen="True"
HorizontalAlignment="Stretch" CanUserSortColumns="False"
ItemsSource="{Binding InvStockLedgerModelList,Mode=TwoWay}"
IsReadOnly="True" SelectedItem="{Binding InvStockLedgerModel,Mode=TwoWay}">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="物料名称" Binding="{Binding MaterialModel.Mat_Name,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="会计年度" Binding="{Binding StockLedger_Year,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="会计期间" Binding="{Binding StockLedger_Period,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="期初库存数量" Binding="{Binding StockLedger_BAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="期初库存金额" Binding="{Binding StockLedger_BMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="收入数量" Binding="{Binding StockLedger_IAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="收入金额" Binding="{Binding StockLedger_IMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="发出数量" Binding="{Binding StockLedger_OAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="发出金额" Binding="{Binding StockLedger_OMoney,Mode=TwoWay}" Width="100"/>
<data:DataGridTextColumn Header="期末数量" Binding="{Binding StockLedger_EndAmount,Mode=TwoWay}"/>
<data:DataGridTextColumn Header="期末金额" Binding="{Binding StockLedger_EndMoney,Mode=TwoWay}" Width="100"/>
</data:DataGrid.Columns>
<!--内置两个触发器
判断双击是否在同一行进行的-->
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding DataGridSelectionCommand}" CommandParameter="{Binding SelectedItem,ElementName=dglist}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding MouseLeftButtonUpCommand}" CommandParameter="{Binding SelectedItem,ElementName=dglist}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</data:DataGrid>
<Border Grid.Row="2" BorderThickness="1,0,1,1" BorderBrush="#6c7175" Margin="5,0,5,0" >
<Grid x:Name="gridFooter" HorizontalAlignment="Stretch" VerticalAlignment="Top" >
<Grid.ColumnDefinitions>
<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="3" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_BAmount" />
<sdk:Label Grid.Column="4" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_BMoney" />
<sdk:Label Grid.Column="5" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_IAmount" />
<sdk:Label Grid.Column="6" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_IMoney" />
<sdk:Label Grid.Column="7" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_OAmount"/>
<sdk:Label Grid.Column="8" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_OMoney" />
<sdk:Label Grid.Column="9" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_EndAmount"/>
<sdk:Label Grid.Column="10" FontSize="13" BorderThickness="1,0,0,0" BorderBrush="#6c7175" x:Name="lblStockLedger_EndMoney"/>
</Grid>
</Border>
</Grid>
cs代码:
View Code
public DelegateCommand DataGridSelectionCommand { protected set; get; }//选择datagrid行命令
public DelegateCommand MouseLeftButtonUpCommand { protected set; get; }//单击行命令
DataGridSelectionCommand = new DelegateCommand(DoDataGridSelectionCommand);//命令初始化
MouseLeftButtonUpCommand = new DelegateCommand(DoMouseLeftButtonUpCommand);
//定义一个辅助变量
public static bool IsDoubleClick = true;
void DoMouseLeftButtonUpCommand(object param)//执行单击命令
{
if (param == null) return;
IsDoubleClick = !IsDoubleClick;
if (!IsDoubleClick && InvStockLedgerModel == param as InvStockLedgerModel)//判断datagrid选择的行和单击行是不是同一行
{
//绑定和显示子页面数据
//可以在此处写 弹出窗体及 绑定数据。。。。
RequestService.Sent(StockManageUriNames.GetInvStockListModelList, InvStockLedgerModel,
delegate(object sent, ResponseArgs args)
{
var InvStockListModelList = Container.Resolve<IInvStockListViewModel>();
InvStockListModelList.InvStockListModelList = args.JsonResponse.GetPostData<IList<InvStockListModel>>();
InvStockListModelList.GetStockListSum();//计算合计行
InvStockListModelList.View.Show();//显示窗体
});
}
}
void DoDataGridSelectionCommand(object param)//执行datagrid行选择命令
{
if(param==null)return;
InvStockLedgerModel = param as InvStockLedgerModel;//将选择的行 赋予属性
IsDoubleClick = View.ViewControl.dglist.SelectedIndex == -1;
}
大功告成!!!
作者:记忆逝去的青春
出处:http://www.cnblogs.com/lukun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过http://www.cnblogs.com/lukun/ 联系我,非常感谢。