一、简介
开销小(较少的装箱解箱):
DateTime? dtEnd = null;
//dtEnd = obj as DateTime;//不能用
//var dtEnd = obj;//可以考虑
dtEnd = (DateTime)obj;//强制转换
但是我我们有时候想要,一次性可以传更多的东西(开销大):
dtEnd = (DateTime)obj;
DatePicker aa = obj as DatePicker;
string bb = aa.Text;
DateTime dd = (DateTime)aa.SelectedDate;
二、附件
.xmal程序:
<UserControl x:Class="KeenRay.Modules.History.Views.ExInPortDlg"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cc="clr-namespace:KeenRay.Controls;assembly=KeenRay.Controls"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:KeenRay.Modules.History.Views"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="270" d:DesignWidth="483">
<Grid Name="rootGrid" Background="#dbdce1">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="50"/>
<RowDefinition Name="hidedRow1" Height="0"/>
<RowDefinition />
</Grid.RowDefinitions>
<Canvas Grid.Row="0">
<Label Canvas.Left="40" Content="选项:"></Label>
</Canvas>
<Canvas Grid.Row="1">
<RadioButton Name="radioImport" Content="导入" Canvas.Left="109" Canvas.Top="18" IsChecked="{Binding RadioImportIsChecked,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding radioImportCheckedCommand}" CommandParameter="{Binding ElementName = radioImport}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Name="radioExport" Content="导出" Canvas.Left="300" Canvas.Top="18" IsChecked="{Binding RadioExportIsChecked,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding radioExportCheckedCommand}" CommandParameter="{Binding ElementName = radioExport}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</Canvas>
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="40"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Canvas Grid.Row="0">
<Label Content="导出选项:" Canvas.Left="40" Canvas.Top="6"/>
</Canvas>
<Canvas Grid.Row="1">
<RadioButton Name="radioExportCurSelect" Canvas.Left="109" Canvas.Top="15" Content="导出当前选择检查" IsChecked="{Binding radioExportCurSelectIsChecked,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding radioExportCurSelectCheckedCommand}" CommandParameter="{Binding ElementName = radioExportCurSelect}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton Name="radioExportDateRange" Canvas.Left="300" Canvas.Top="15" Content="导出时间段检查" IsChecked="{Binding radioExportDateRangeIsChecked,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding radioExportDateRangeCheckedCommand}" CommandParameter="{Binding ElementName = radioExportDateRange}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
</Canvas>
<Canvas Grid.Row="2">
<DatePicker Name="dpkDateStart" Style="{StaticResource ExPortDatePickerStyle}" Canvas.Left="109" Width="150">
<i:Interaction.Triggers>
<!--默认加载-->
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding dpkDateStartLoadedCommand}" CommandParameter="{Binding ElementName = dpkDateStart}"/>
</i:EventTrigger>
<!--选中日期-->
<i:EventTrigger EventName="SelectedDateChanged">
<i:InvokeCommandAction Command="{Binding dpkDateStartSelectedDateChangedCommand}" CommandParameter="{Binding ElementName = dpkDateStart}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DatePicker>
<DatePicker Name="dpkDateEnd" Style="{StaticResource ExPortDatePickerStyle}" Canvas.Left="300" Width="150" SelectedDate="" Text="" Tag="">
<i:Interaction.Triggers>
<!--默认加载-->
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding dpkDateEndLoadedCommand}" CommandParameter="{Binding ElementName = dpkDateEnd}"/>
</i:EventTrigger>
<!--选中日期-->
<i:EventTrigger EventName="SelectedDateChanged">
<i:InvokeCommandAction Command="{Binding dpkDateEndSelectedDateChangedCommand}" CommandParameter="dpkDateEnd"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DatePicker>
</Canvas>
</Grid>
<Canvas Grid.Row="3">
<cc:ImageButton Content="{DynamicResource History.PrintSetting.Operate.Content}" Width="100" Height="30" Canvas.Right="200" Canvas.Left="246" Canvas.Top="5" FontSize="18" IsDefault="True" Foreground="#606467" DefaultImage="{StaticResource Public.EmptyButton122x52.Enable.Icon}" PressedImage="{StaticResource Public.EmptyButton112x52.Touches.Icon}" Command="{Binding OperateCommand}"></cc:ImageButton>
<cc:ImageButton Content="{DynamicResource History.PrintSetting.Cancel.Content}" Width="100" Height="30" Canvas.Right="5" Canvas.Left="351" Canvas.Top="5" FontSize="18" Foreground="#606467" DefaultImage="{StaticResource Public.EmptyButton122x52.Enable.Icon}" PressedImage="{StaticResource Public.EmptyButton112x52.Touches.Icon}" Command="{Binding CancelCommand}"></cc:ImageButton>
</Canvas>
</Grid>
</UserControl>
.cs程序
private void DpkDateEnd_SelectedDateChanged(object obj)
{
//dtEnd = this.dpkDateEnd.SelectedDate;
//var dtEnd = obj;
dtEnd = (DateTime)obj;
DatePicker aa = obj as DatePicker;
string bb = aa.Text;
DateTime dd = (DateTime)aa.SelectedDate;
等等
}