在网上搜了很久也没有答案。 还是找到了,共享一下。 也许很多人需要 :)
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridAutomationPeer lvap = new DataGridAutomationPeer(dataGrid1);
var svap = lvap.GetPattern(PatternInterface.Scroll) as ScrollViewerAutomationPeer;
var scroll = svap.Owner as ScrollViewer;
scroll.ScrollToVerticalOffset(dataGrid1.Items.Count - 1);
}
乱来的人也喜欢把view中的控件传给viewmodel :)
public DelegateCommand<Button> BtnClickCommand { get; set; }
BtnClickCommand = new DelegateCommand<Button>(BtnClick); //实例化
private void BtnClick(Button btn)
{
string strBtnName = btn.Name;//使用
}
TextBox:
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
<TextBox Name="textBox" Width="240" Text="{Binding Input}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonUp" >
<i:InvokeCommandAction Command="{Binding SizeChangedCommand}"
CommandParameter="{Binding ElementName=textBox}" >
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
public DelegateCommand<TextBox> SizeChangedCommand { get; set; }
SizeChangedCommand = new DelegateCommand<TextBox>(SizeChangedCommandExecute);
private void SizeChangedCommandExecute(TextBox tb)
{
MessageBox.Show(tb.Text);
}
private string DateDiff(DateTime DateTime1, DateTime DateTime2)
{
string dateDiff = null;
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
dateDiff = ts.Days.ToString()+"天"
+ ts.Hours.ToString()+"小时"
+ ts.Minutes.ToString()+"分钟"
+ ts.Seconds.ToString()+"秒"
return dateDiff;
}