I'm new to this and I'm at my wits end so I'm reaching out for help.
I'm trying to pass the selected dates to a property that I can then use in a sql query, but the dates past are the default and the the newly selected dates. Below is my xaml, viewmodel and sqlquery class. Any help would be greatly appreciated.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding Main, Source={StaticResource Locator}}" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="NSP_Commission.MainWindow" Title="NSP Commission Tracker" Height="350" Width="525"><Grid><Grid.RowDefinitions><RowDefinition Height="40"/><RowDefinition Height="*"/></Grid.RowDefinitions><Label Margin="5,5,6.103,9" HorizontalAlignment="Left" Width="110" Content="Select Date Range:"/><DatePicker x:Name="dpBeginDate" HorizontalAlignment="Left" Margin="120,5,0,9" Width="120" SelectedDate="{Binding BeginDate, Mode=TwoWay}"/><DatePicker x:Name="dpEndDate" HorizontalAlignment="Left" Margin="270,5,0,9" Width="120" SelectedDate="{Binding EndDate, Mode=TwoWay}"/><TextBox Text="To" HorizontalAlignment="Left" Margin="242,6,0,10" Width="28" BorderBrush="{x:Null}"/><Button x:Name="ImportButton" Content="Import" HorizontalAlignment="Right" Margin="0,8,5,10" Width="75" d:LayoutOverrides="Height" Command="{Binding ImportData}"/></Grid></Window>
namespace NSP_Commission.ViewModel { public class MainViewModel : ViewModelBase { public MainViewModel() { if (IsInDesignMode) { // Code runs in Blend --> create design time data. } else { ImportData = new RelayCommand(() => ImportDataExecute(), () => true); } } public ICommand ImportData { get; private set; } private void ImportDataExecute() { Invoice_Hdr ih = new Invoice_Hdr(); ih.LoadInvoice_Hdr(); Invoice_Dtl id = new Invoice_Dtl(); id.LoadInvoice_Dtl(); MessageBox.Show("Import Complete!"); } private DateTime _beginDate = DateTime.Today; public DateTime BeginDate { get { return _beginDate; } set { _beginDate = value; RaisePropertyChanged("BeginDate"); } } private DateTime _endDate = DateTime.Today; public DateTime EndDate { get { return _endDate; } set { _endDate = value; RaisePropertyChanged("EndDate"); } } } }
namespace NSP_Commission.CustomCode.SqlQuerys { class Invoice_Hdr : MainViewModel { public string LoadInvoice_Hdr() { string myqueryString; DateTime myBeginDate; DateTime myEndDate; //Assign Report Parameters Based on Logged In User //SelectedDates sd = new SelectedDates(); myBeginDate = BeginDate; myEndDate = EndDate; myqueryString = "blah blah " + BeginDate + "; return myqueryString; } } }