Just tried a GUI code and at first I could see text, buttons after first compile. Then I tried to hook up the buttons to the RadioButton, after compiling this all I was able to see was plain white.
The .xaml code:
<Window x:Class="GUItest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GUItest"
mc:Ignorable="d"
Title="MainWindow" Height="855" Width="1628">
<Grid RenderTransformOrigin="0.500,0.525" Margin="0,0,0,-6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="76"/>
</Grid>
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="10,305,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Height="150" Width="237" RenderTransformOrigin="0.476,0.498"/>
<RadioButton x:Name="ABC" Content="ABC" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="DEF" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
</Grid>
<Grid>
<RadioButton x:Name="ABCButton" Content="ABC" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="DEFButton" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="0,0,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="238" Height="143" RenderTransformOrigin="0.50-53,0.501">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="-0.1"/>
<RotateTransform/>
<TranslateTransform X="-0.332"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Grid>
</Window>
And this is the .xaml.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GUItest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (ABCButton.IsChecked == true)
{
MessageBox.Show("ABC");
}
else if (DEFButton.IsChecked == true)
{
MessageBox.Show("DEF");
}
}
}
}
This is just made by me to better understand the GUI.
All of your items fall in the first column and your ColumnWidth of the first one is 0*. This means that the width will be 0 (times) x, which results in a width of 0.
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
Try to make this * or 2* or something, or place the items in a different column.
Good luck.
Edit:
Placing the items in a different column can be done by:
<Grid Grid.Column="1">
<TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Width="76"/>
</Grid>
<Grid Grid.Column="1"> <!-- Here the 1 means place this grid in the first column of the main grid -->
<TextBlock HorizontalAlignment="Left" Margin="10,305,0,0" TextWrapping="Wrap" Text="Select an option:" VerticalAlignment="Top" Height="150" Width="237" RenderTransformOrigin="0.476,0.498"/>
<RadioButton x:Name="ABC" Content="ABC" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
<RadioButton x:Name="DEF" Content="DEF" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
</Grid>
Related
I am developing an application that will work with a database using EntityFrameWork.
I wrote such a WPF window, made bindings by names in the Tour table, to display information about tours.
But on startup, I see empty fields. Who can tell what the problem is?
List loaded into ListView
Code XAML:
<Window x:Class="ToursApp.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ToursApp"
mc:Ignorable="d"
Title="Tours" Height="450" Width="800">
<Grid>
<ListView Grid.Row="1" x:Name="LViewsTours">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="20" Width="400">
<Grid.RowDefinitions>
<RowDefinition Height="70"></RowDefinition>
<RowDefinition Height="310"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Image Width="400" Grid.Row="1" Stretch="UniformToFill" HorizontalAlignment="Center" Margin="5">
<Image.Source>
<Binding Path="ImagePreview">
<Binding.TargetNullValue>
<ImageSource>Resources/placeholder.png</ImageSource>
</Binding.TargetNullValue>
</Binding>
</Image.Source>
</Image>
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" TextAlignment="Center" Width="390" TextWrapping="Wrap" HorizontalAlignment="Center" Margin="5 5" FontSize="26" Grid.Row="0"></TextBlock>
<TextBlock Text="{Binding Price}" Grid.Row="2" Margin="5 5 5 15" HorizontalAlignment="Center" FontSize="26" FontWeight="Bold" ></TextBlock>
<TextBlock Text="{Binding TicketCount}" Grid.Row="3" FontSize="14" HorizontalAlignment="Right"></TextBlock>
<TextBlock Text="{Binding IsActual}" Grid.Row="3" FontSize="14" HorizontalAlignment="Left"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
CODE C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ToursApp
{
public partial class simpleUser : Window
{
public simpleUser()
{
InitializeComponent();
var currentTours = TourBaseEntitiesDB.GetContext().Tour.ToList();
MessageBox.Show(currentTours.Count().ToString());
LViewsTours.ItemsSource = currentTours;
}
}
}
Ожидаемый результат:
Результат который я получаю:
UPD Попробовал сделать вывод в DataGrid, без изменений, получаю пустые строки:
Recently I'm trying to learn some Windows 10 UWP app developments. And now I encountered a strange issue, where there is a white ribbon in the bottom of my app, see here:
If I drag and enlarge the app window, then there will be another white ribbon on the top, see here:
Here is my XAML for the UI:
<Page
x:Class="ApodidaeCore.ClockMainUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ApodidaeCore"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid RequestedTheme="Dark" Margin="0,0,0,38" Height="600" Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="439*"/>
<RowDefinition Height="161*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="205*"/>
<ColumnDefinition Width="819*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="hourTextBlock" HorizontalAlignment="Left" Height="191" TextWrapping="Wrap" Text="00" VerticalAlignment="Top" Width="205" Foreground="White" FontSize="170" Margin="15.2,98,0,0" Grid.Column="1" />
<TextBlock x:Name="clockSymbolTextBlock" HorizontalAlignment="Left" Height="141" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="38" Foreground="White" FontSize="105" FontWeight="Bold" Margin="244.2,130,0,0" Grid.Column="1"/>
<TextBlock x:Name="minuteTextBlock" HorizontalAlignment="Left" Height="197" TextWrapping="Wrap" Text="00" VerticalAlignment="Top" Width="218" Foreground="White" FontSize="170" Margin="308.2,98,0,0" Grid.Column="1"/>
<TextBlock x:Name="weatherInfoTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="25" Margin="188.2,331,0,0" Text="Unknown" Width="314" Height="33" Grid.Column="1"/>
<TextBlock x:Name="notificationTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="No new notification" VerticalAlignment="Top" Foreground="White" FontSize="25" Margin="188.2,369,0,0" Height="30" Width="314" Grid.Column="1"/>
<Image x:Name="weatherInfoIconImage" HorizontalAlignment="Left" Height="100" Margin="67.2,321,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1"/>
</Grid>
What should I do to fix this? Any suggestions? Thanks in advance!
Jackson.
Got fixed, silly me!
I've wrongly set the grid height and the margin.
Remove those two variables will fix that issue.
Change this:
<Grid RequestedTheme="Dark" Margin="0,0,0,38" Height="600" Background="Black">
to this:
<Grid RequestedTheme="Dark" Background="Black">
I'm Trying A small Login universal Windows app.
I have LoginPage.xaml and signup button in that.
In my LoginPage.xaml.cs file I have signup_click method In that method I have to pass tha signuppage.xaml.
Here is my code I'm getting error.
<Page
x:Class="LoginApp.MainPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LoginApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<!--Title-->
<TextBlock Text="Login Page" Foreground="Black" FontSize="40"/>
<!--UserName-->
<TextBlock Text="UserID" Foreground="Black" FontSize="30"/>
<TextBox BorderBrush="LightGray" Name="UserName" GotFocus="UserName_GotFocus"/>
<!--Password-->
<TextBlock Foreground="Black" Text="Password" Margin="9,-7,0,0" FontSize="30"/>
<PasswordBox BorderBrush="LightGray" Name="PassWord" GotFocus="UserName_GotFocus" />
<!--Login Button-->
<Button Content="Login" Background="#FF30DABB" Name="Login" Click="Login_Click" Width="338" />
<!-- Registration Button-->
<Button Content="Registration" Background="#FF30DABB" Name="SignUp" Click="SignUp_Click" Width="338"/>
</StackPanel>
</Grid>
</Page>
This is my LoginPage.xaml.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace LoginApp.Model
{
class LoginPage
{
public void Login_Click(object sender, RoutedEventArgs e) {
}
public void SiguUp_Click(object sender, RoutedEventArgs e) {
NavigationService.Navigate(new Uri("/Views/SignUpPage.xaml", UriKind.Relative));
}
}
}
This is my LoginPage.xaml.cs.
error is pointing to NavigationService "The name Does not exist in current context".
I'm new to c# Don't know The reason for this error.
Anyone Help me what is wrong a how to correct this error.
I'm Very much thankful to them.
And in my SignUp.xaml I have a Text Box With the name TxtUserName.
In my SignUp.xaml.cs I'm validating the text box with any name.
While using this the error message is like "The name txtUsernname does not exist in current context".
Below is my code.
<Page
x:Class="LoginApp.SignUpPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LoginApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid Margin="10,10,-5,-10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="User Registration :" Grid.Row="0" FontSize="40" Foreground="Black"/>
<TextBlock Text="UserName" Grid.Row="1" Foreground="Black" Margin="0,25,0,0"/>
<TextBox Name="TxtUserName" BorderBrush="LightGray" Grid.Row="1" Margin="100,0,0,0" GotFocus="Txt_GotFocus"/>
<TextBlock Text="Password:" Grid.Row="2" Margin="0,25,0,0" Foreground="Black"/>
<PasswordBox Name="TxtPwd" BorderBrush="LightGray" Grid.Row="2" Margin="100,0,0,0" GotFocus="pwd_GotFocus"/>
<TextBlock Text="Address:" Grid.Row="3" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtAddr" BorderBrush="LightGray" Margin="100,0,0,0" GotFocus="Txt_GotFocus"/>
<TextBlock Text="Gender:" Grid.Row="4" Margin="0,25,0,0" Foreground="Black"/>
<RadioButton Name="GenMale" Background="LightGray" Grid.Row="4" Margin="100,0,0,0" Content="Male" Foreground="Black"/>
<RadioButton Name="GenFemale" Background="LightGray" Grid.Row="4" Margin="200,0,0,0" Content="Female" Foreground="Black"/>
<TextBlock Text="Phone No:" Grid.Row="5" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtPhNo" Grid.Row="5" Margin="100,0,0,0" Foreground="LightGray" MaxLength="10" InputScope="Digits" GotFocus="Txt_GotFocus"/>
<TextBlock Text="EmailID:" Grid.Row="6" Margin="0,25,0,0" Foreground="Black"/>
<TextBox Name="TxtEmail" Grid.Row="6" Margin="100,0,0,0" GotFocus="TxtGotFocus"/>
<Button BorderBrush="Transparent" Background="#FF30DABB" Content="Submit" Name="BtnSubmit" Click="Submit_Click" Grid.Row="7" Margin="0,25.667,0,-41.667" Width="345"/>
</Grid>
</Grid>
</Page>
This is SignUppage.xaml.
using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.UI.Xaml;
namespace LoginApp.Model
{
class SignUpPage
{
IsolatedStorageFile ISOFile = IsolatedStorageFile.GetUserStoreForApplication();
public void Submit_Click(object sender, RoutedEventArgs e) {
if (!Regex.IsMatch(TxtUserName.Text.Trim(), #"^[A-Za-z_][a-zA-Z0-9_\s]*$")) {
MessageBox.Show("Invalid UserName");
}
}
}
}
This is SignUpPage.xaml.cs
Can anyone help me to solve this.
If I understood well all your code, you have separate yours *.xaml (in /Views) et yours *.xaml.cs (in /Model).
I recommend you to put yours .xaml and .xaml.cs together in Views because *.xaml.cs is not a Model but the code behind. A model is more of an element of your database (roughly).
Then, your *.xaml.cs should be implementing System.Windows.Controls.Page, this is an exemple :
public partial class LoginPage : Page
Also don't forget to create the constructor (but normally if you use the file creator of Visual Studio, it will create the skeleton for the file you want to create) :
public LoginPage()
{
InitializeComponent();
}
Finally if with that it is still not working, be sure that you are using the right references as Sebastian Schulz told you.
i have a pop up and i want to close it when i tap anywhere outside the pop up. i searched and everyone advised me to use the property IsLightDismissEnabled; however if i touch outside, it will only remove the pop oup leaving everything inactive with a grey like screen as if it doesnt close the pop up completely
this is my code snippet:
<Popup x:Name="logincontroler" IsOpen="False" Margin="0,190,896,276" IsLightDismissEnabled="True">
<StackPanel Height="300" Width="470" x:Name="popup" FlowDirection="RightToLeft">
<Grid Width="470" Background="White" >
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<RichEditBox Grid.Row="1" Height="250" TextWrapping="Wrap" FontSize="20" Name="notesPopupTextBox" FlowDirection="LeftToRight"/>
<StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFE3E3E5">
<Button Name="CanclePopupButton" Content="Cancel" Width="64" Height="64" Click="CanclePopupButton_Click" />
<Button Name="ClearNotePopupButton" Content="Clear" Width="64" Height="64" Click="ClearNotePopupButton_Click" />
<Button Name="saveNoteButton" Content="Save" Width="64" Height="64" Click="saveNoteButton_Click" />
<TextBlock FontWeight="Medium" FontSize="40" Foreground="#2a2a86" Margin="170 12 0 0">Note</TextBlock>
</StackPanel>
</Grid>
</StackPanel>
</Popup>
this is my code for the events
private void ShowButton_Click(object sender, RoutedEventArgs e)
{
logincontroler.IsOpen = true;
flipView1.IsEnabled = false;
}
private void CanclePopupButton_Click(object sender, RoutedEventArgs e)
{
logincontroler.IsOpen = false;
flipView1.IsEnabled = true;
}
Am I missing anything?
thank you in advance
Are you sure you don't have some other code in the App that you are not showing us?
There should be no Gray box behind the Popup.
I have just tested your code on an empty Windows 8.1 (XAML+C#) App and it works fine.
Try creating and Blank Windows 8.1 App and make you MainPage like this:
MainPage.xaml
<Page
x:Class="App19.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App19"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
RequestedTheme="Light">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Popup x:Name="logincontroler" IsOpen="False" Margin="0,190,896,276" IsLightDismissEnabled="True">
<StackPanel Height="320" Width="470" x:Name="popup" FlowDirection="RightToLeft">
<Grid Width="470" Background="BurlyWood" >
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<RichEditBox Grid.Row="1" Height="250" TextWrapping="Wrap" FontSize="20" Name="notesPopupTextBox" FlowDirection="LeftToRight"/>
<StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFE3E3E5">
<Button Name="CanclePopupButton" Content="Cancel" Width="64" Height="64" />
<Button Name="ClearNotePopupButton" Content="Clear" Width="64" Height="64" />
<Button Name="saveNoteButton" Content="Save" Width="64" Height="64" />
<TextBlock FontWeight="Medium" FontSize="40" Foreground="#2a2a86" Margin="170 12 0 0">Note</TextBlock>
</StackPanel>
</Grid>
</StackPanel>
</Popup>
<Button Content="Show Popup" HorizontalAlignment="Left" Margin="692,260,0,0" VerticalAlignment="Top" Click="ShowButton_Click"/>
</Grid>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App19
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void ShowButton_Click(object sender, RoutedEventArgs e)
{
logincontroler.IsOpen = true;
}
}
}
This has to work.
And comparing this with your solution should help you find the problem. If not, just edit your question with more information. (more code)
Note: I removed the click events from your popup, they were not needed to exemplify your problem, right?
I'm searching everywhere on forums and msdn and it says that SelectedDate, DisplayStartDate, DisplayEndDate, whether in XAML or C# will make it work, but everytime I try to use any of theses, I'm getting missing directive reference or assembly. How do I fix this? I know I'm missing a reference, but what using System or xlmns....? Please tell me how I can make it work, so I don't get errors when I try to use the property.
XAML Code & References:
x:Class="Data_Query.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<toolkit:DatePicker HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="dateOfBirthPicker" ValueChanged="dateOfBirthPicker_ValueChanged" Margin="0,369,0,0"/>
C# Code References:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows.Media; // added to support SolidColorBrush, FontWeights, etc...
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Data_Query.Resources;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Text.RegularExpressions;
Full XAML Code:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="JP APPS" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="Data Query" Margin="0,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--Height of the Grid has to be greater than the ScrollViewer's Height to make it scrollable.-->
<!--Removing the ScrollViewer's Height enables you to see the entire page in a transparent-like view-->
<ScrollViewer Height="605" Width="480" HorizontalAlignment="Left" Margin="0,0,0,-163" VerticalAlignment="Top" Grid.Row="1">
<Grid MinHeight="605" Height="770">
<TextBlock x:Name="firstNameTBL" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="First Name:" VerticalAlignment="Top"/>
<TextBox x:Name="firstNameTB" InputScope="PersonalFullName" KeyUp="TextBox_KeyUp" LostFocus="firstNameTB_LostFocus" HorizontalAlignment="Left" Height="72" Margin="0,42,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="253"/>
<TextBlock x:Name="lastNameTBL" HorizontalAlignment="Left" Margin="10,119,0,0" TextWrapping="Wrap" Text="Last Name:" VerticalAlignment="Top"/>
<TextBox x:Name="lastNameTB" InputScope="PersonalFullName" KeyUp="TextBox_KeyUp" LostFocus="lastNameTB_LostFocus" HorizontalAlignment="Left" Height="72" Margin="0,151,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="253"/>
<TextBlock x:Name="emailAddressTBL" HorizontalAlignment="Left" Margin="10,228,0,0" TextWrapping="Wrap" Text="Email Address:" VerticalAlignment="Top"/>
<TextBox x:Name="emailAddressTB" InputScope="EmailSmtpAddress" KeyUp="TextBox_KeyUp" LostFocus="emailAddressTB_LostFocus" HorizontalAlignment="Left" Height="72" Margin="0,260,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="253"/>
<TextBlock x:Name="dateOfBirthTBL" HorizontalAlignment="Left" Margin="10,337,0,0" TextWrapping="Wrap" Text="Date of Birth:" VerticalAlignment="Top"/>
<toolkit:DatePicker HorizontalAlignment="Left" VerticalAlignment="Top" x:Name="dateOfBirthPicker" ValueChanged="dateOfBirthPicker_ValueChanged" Margin="0,369,0,0"/>
<TextBlock Name="genderTBL" HorizontalAlignment="Left" Margin="10,447,0,0" TextWrapping="Wrap" Text="Gender:" VerticalAlignment="Top"/>
<RadioButton Name="maleRB" GroupName="genderLB" Tap="maleRB_Tap" Content="Male" Checked="maleRB_Checked" HorizontalAlignment="Left" Margin="0,479,0,0" VerticalAlignment="Top"/>
<RadioButton Name="femaleRB" GroupName="genderLB" Tap="femaleRB_Tap" Content="Female" Checked="femaleRB_Checked" HorizontalAlignment="Left" Margin="113,479,0,0" VerticalAlignment="Top"/>
<TextBlock Name="disabilityTBL" HorizontalAlignment="Left" Margin="10,551,0,0" TextWrapping="Wrap" Text="Do you have a disability?" VerticalAlignment="Top"/>
<ToggleButton Name="yesTBU" Content="Yes" Tap="ToggleButton_Tap" Checked="yesTBU_Checked" Height="100" Width="150" Margin="0,583,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ToggleButton Name="noTBU" Content="No" Tap="ToggleButton_Tap" Checked="noTBU_Checked" Height="100" Width="150" Margin="151,583,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Content="Submit" HorizontalAlignment="Stretch" Margin="0,0,250,10" VerticalAlignment="Bottom" Click="submitButton" Height="77"/>
<Button Content="Reset All" HorizontalAlignment="Stretch" Margin="235,0,10,10" VerticalAlignment="Bottom" Click="resetButton" Height="77"/>
</Grid>
</ScrollViewer>
</Grid>
If you are using WPF you do not need to be using the toolkit namespace which points to the windows phone.
In the example project I am working with this is all I have to do to get the DatePicker working.
<Window x:Class="testDatePicker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
</Grid.Resources>
<DatePicker DisplayDateStart="2014/02/28" DisplayDateEnd="2014/02/28" SelectedDate="2014/02/28"></DatePicker>
</Grid>
If you want them to only be able to select today, then they really can't select anything. Set the default value to be DateTime.Today and set IsEnabled="false" on the control.
If you want to stop people from selecting any date beyond today, then you can use the BlackoutDates property of a DatePicker. Like this:
myDatePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.Now.AddDays(1), DateTime.MaxValue));
You should do this around the time the page is initialised.