A
Alex. O. Koranteng
The button event handler for XAML page not firing for Textbox field, but it
fires for the date selected value for calendar. I have listed code file code
file below. Any suggestions will be appreciated.
<UserControl
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="HelloSilverLight.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Azure" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition
Height="220"/>
<RowDefinition
Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75" />
<ColumnDefinition Width="325" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="name1" Text="Name:" Grid.Row="0"
Grid.Column="0"></TextBlock>
<TextBlock Text="Date:" Grid.Row="1" Grid.Column="0"></TextBlock>
<TextBlock x:Name="message1" Text="Message:" Grid.Row="2"
Grid.Column="0" Grid.ColumnSpan="2"></TextBlock>
<TextBox Text="Your Name" Width="150" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="1"></TextBox>
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" >
<basics:Calendar SelectionMode="SingleDate"
HorizontalAlignment="Left" x:Name="cal1"></basics:Calendar>
<Button Click="okButton_Click" x:Name="okButton" Width="75"
Height="25" HorizontalAlignment="Left" Content="OK" ></Button>
</StackPanel>
</Grid>
</UserControl>
Also below is my code behind for the page.XAML.cs flle.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace HelloSilverLight
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
string dateString;
if (cal1.SelectedDate == null)
{
dateString = "<date not selected>";
}
else
{
dateString = cal1.SelectedDate.ToString();
}
string s = message1.Text = "Hi " + name1.Text + "\n" +
"Selected Date: " + dateString;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}
fires for the date selected value for calendar. I have listed code file code
file below. Any suggestions will be appreciated.
<UserControl
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="HelloSilverLight.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Azure" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition
Height="220"/>
<RowDefinition
Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75" />
<ColumnDefinition Width="325" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="name1" Text="Name:" Grid.Row="0"
Grid.Column="0"></TextBlock>
<TextBlock Text="Date:" Grid.Row="1" Grid.Column="0"></TextBlock>
<TextBlock x:Name="message1" Text="Message:" Grid.Row="2"
Grid.Column="0" Grid.ColumnSpan="2"></TextBlock>
<TextBox Text="Your Name" Width="150" HorizontalAlignment="Left"
Grid.Row="0" Grid.Column="1"></TextBox>
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" >
<basics:Calendar SelectionMode="SingleDate"
HorizontalAlignment="Left" x:Name="cal1"></basics:Calendar>
<Button Click="okButton_Click" x:Name="okButton" Width="75"
Height="25" HorizontalAlignment="Left" Content="OK" ></Button>
</StackPanel>
</Grid>
</UserControl>
Also below is my code behind for the page.XAML.cs flle.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace HelloSilverLight
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
string dateString;
if (cal1.SelectedDate == null)
{
dateString = "<date not selected>";
}
else
{
dateString = cal1.SelectedDate.ToString();
}
string s = message1.Text = "Hi " + name1.Text + "\n" +
"Selected Date: " + dateString;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}