create popup using silverlight and add a data grid to the popup - c#

I need to add a grid to a popup in Silverlight project. I have added this code in the mainpage.xaml.cs file I have created a popup.
but I need to add a grid showing a table from the database.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
popup p = new Popup();Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Black);
border.BorderThickness = new Thickness(5.0);
StackPanel panel1 = new StackPanel();
panel1.Background = new SolidColorBrush(Colors.LightGray);
Button button1 = new Button();
button1.Content = "Close";
button1.Margin = new Thickness(2.0);
button1.Click += new RoutedEventHandler(button1_Click);
TextBlock textblock1 = new TextBlock();
textblock1.Text = "The popup control";
textblock1.Margin = new Thickness(5.0);
panel1.Children.Add(textblock1);
panel1.Children.Add(button1);
border.Child = panel1;
Grid grid1 = new Grid();
// i need to bind this grid to data from the sql database and attach this grid to the popup
// Set the Child property of Popup to the border
// which contains a stackpanel, textblock and button.
p.Child = border;
p.DataContext =
// Set where the popup will show up on the screen.
p.VerticalOffset = 200;
p.HorizontalOffset = 300;
// Open the popup.
p.IsOpen = true;
}

The Grid is a layout control, and not for displaying tables. For tabular data, you'll need a DataGrid control.
List<Customer> customerList = new List<Customer>();
var dataGrid = new DataGrid();
dataGrid.ItemsSource = customerList;
Popup popup = new Popup();
popup.Child = dataGrid;
popup.IsOpen = true;

Related

I need to add a DataGridView to the form dynamically

private void btnShowCausali_Click(object sender, EventArgs e)
{
DataGridView Dati = new DataGridView();
Dati.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
Dati.Location = new System.Drawing.Point(120, 40);
Dati.Name = "Dati";
Dati.RowTemplate.Height = 24;
Dati.Size = new System.Drawing.Size(979, 458);
Dati.TabIndex = 1;
Dati.Visible = true;
Dati.Columns.Add("id", "ID");
Dati.Columns.Add("causaliname", "Nome Causale");
Dati.Columns.Add("Identificationcode", "Codice Identificativo");
Dati.Columns.Add("expired", "Data di Scadenza");
grpDatore.Controls.Add(Dati);
}
When I run this code the DataGridView does not appear on the form. Just in case it could create problem, the button btnShowCausali get created on the form load.
public void Form1_Load(object sender, EventArgs e)
{
Button btnShowCausali = new Button();
btnShowCausali.Text = "Causali";
btnShowCausali.Location = new Point(20, 20);
btnShowCausali.Size = new Size(120, 40);
}
By the way, I don't know why the button actually gets created but the DataGridView does not.
Your event handler btnShowCausali_Click is not attached to the button in Form1_Load. Are you sure it is called?
I also do not see adding this button to any container (Form, Panel, ...)
Your DataGridView will be added to grpDatore control (not form) so have that in mind when you set Location.
Attach event:
btnShowCausali.Click += btnShowCausali_Click;
First of all, if the button is created dynamically, add it to the UI.
Button btnShowCausali = new Button();
btnShowCausali.Text = "Causali";
btnShowCausali.Location = new Point(20, 20); // Make shure there aren't other controls in this point
btnShowCausali.Size = new Size(120, 40);
this.Controls.Add(btnShowCausali); //Adding the button to the form
Then, you have to attach an event handler for the Click event of the button. In short, you have to tell to the button what to do when it is clicked. You have two options to add an event handler for the click event:
Code: add btnShowCausali.Click += btnShowCausali_Click; after the InitializeComponent function call (in the constructor) or in the Load event of the form. Then add the function btnShowCausali_Click:
private void btnShowCausali_Click(object sender, EventArgs e)
{
DataGridView Dati = new DataGridView();
Dati.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
Dati.Location = new System.Drawing.Point(120, 40);
Dati.Name = "Dati";
Dati.RowTemplate.Height = 24;
Dati.Size = new System.Drawing.Size(979, 458);
Dati.TabIndex = 1;
Dati.Visible = true;
Dati.Columns.Add("id", "ID");
Dati.Columns.Add("causaliname", "Nome Causale");
Dati.Columns.Add("Identificationcode", "Codice Identificativo");
Dati.Columns.Add("expired", "Data di Scadenza");
grpDatore.Controls.Add(Dati); // DataGridView added to grpDatore, not form. Make shure grpDatore is visible.
}
Designer: double click on the button. Visual Studio will do the magic for you.

How to show toast after performing some functionality in windows phone 8

I want to show something like toast after some functionality performed. i-e I have a save button and I want that when it pressed then a toast should be shown with the text Record Saved etc. I read posts that show toasts are only for back-ground agents. I know someone will give me good guidance. please specify some code.
Thanks
You can use the Toast Prompt from the Coding4Fun Toolkit to perform a toast notification via code. After referencing the toolkit (ideally via NuGet) you can use it like this:
ToastPrompt toast = new ToastPrompt();
toast.Title = "Your app title";
toast.Message = "Record saved.";
toast.TextOrientation = Orientation.Horizontal;
toast.MillisecondsUntilHidden = 2000;
toast.ImageSource = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));
toast.Show();
I prefer ProgressIndicator in my apps but you can use Popup or ToastPrompt.
Sample project.
// popup member
private Popup popup;
// creates popup
private Popup CreatePopup()
{
// text
TextBlock tb = new TextBlock();
tb.Foreground = (Brush)this.Resources["PhoneForegroundBrush"];
tb.FontSize = (double)this.Resources["PhoneFontSizeMedium"];
tb.Margin = new Thickness(24, 32, 24, 12);
tb.Text = "Custom toast message";
// grid wrapper
Grid grid = new Grid();
grid.Background = (Brush)this.Resources["PhoneAccentBrush"];
grid.Children.Add(tb);
grid.Width = this.ActualWidth;
// popup
Popup popup = new Popup();
popup.Child = grid;
return popup;
}
// hides popup
private void HidePopup()
{
SystemTray.BackgroundColor = (Color)this.Resources["PhoneBackgroundColor"];
this.popup.IsOpen = false;
}
// shows popup
private void ShowPopup()
{
SystemTray.BackgroundColor = (Color)this.Resources["PhoneAccentColor"];
if (this.popup == null)
{
this.popup = this.CreatePopup();
}
this.popup.IsOpen = true;
}
// shows and hides popup with a delay
private async void ButtonClick(object sender, RoutedEventArgs e)
{
this.ShowPopup();
await Task.Delay(2000);
this.HidePopup();
}
using Windows.UI.Notifications;
var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var txtNodes = toastXmlContent.GetElementsByTagName("text");
txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("First Line"));
txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Second Line" ));
var toast = new ToastNotification(toastXmlContent);
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);

Retrieve row number by a button's click event in DataGrid

I am adding a label and two buttons to the first column of a DataGrid:
//buttons
DataGridTemplateColumn dgc = new DataGridTemplateColumn();
DataTemplate dtm = new DataTemplate();
FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
label.SetValue(Label.ContentProperty, new Binding("Name"));
FrameworkElementFactory button = new FrameworkElementFactory(typeof(Button));
button.SetValue(Button.ContentProperty, "7");
button.SetValue(Button.FontFamilyProperty, new FontFamily("Webdings"));
button.SetValue(Button.HeightProperty, 18.0);
button.AddHandler(Button.ClickEvent, new RoutedEventHandler(previous_event));
FrameworkElementFactory button2 = new FrameworkElementFactory(typeof(Button));
button2.SetValue(Button.ContentProperty, "8");
button2.SetValue(Button.FontFamilyProperty, new FontFamily("Webdings"));
button2.SetValue(Button.HeightProperty, 18.0);
button2.AddHandler(Button.ClickEvent, new RoutedEventHandler(next_event));
FrameworkElementFactory label2 = new FrameworkElementFactory(typeof(Label));
label2.SetValue(Label.ContentProperty, "");
FrameworkElementFactory btnReset = new FrameworkElementFactory(typeof(DockPanel));
btnReset.AppendChild(label);
btnReset.AppendChild(button);
btnReset.AppendChild(button2);
btnReset.AppendChild(label2);
btnReset.SetValue(DockPanel.HorizontalAlignmentProperty, HorizontalAlignment.Right);
btnReset.SetValue(DockPanel.HeightProperty, 24.0);
//set the visual tree of the data template
dtm.VisualTree = btnReset;
dgc.Header = "Events / Time";
dgc.CellTemplate = dtm;
dgc.Width = 300;
dgTimeline.Columns.Add(dgc);
How do I get the row number in which the clicked button is? In the previous_event and next_event methods I have tried:
public void previous_event(object sender, RoutedEventArgs e)
{
Console.WriteLine("prev " + ((DockPanel)((Button)e.OriginalSource).Parent).Parent.GetType());
}
Trying to get DockPanel's parent triggers a NullReferenceException.
When you use a Button inside a DataGrid, the row with the clicked button will automatically be selected. So you can just grab the SelectedIndex of the DataGrid.

Create dynamic dragpanel in asp.net with c#

I want to create ajax dragpanel dynamically and add the controls and panel dynamically.I used the below code for create the control dynamically.But I can`t able to drag it.
enter code here
protected void Page_PreInit(object sender, EventArgs e)
{
DragPanelExtender drg = new DragPanelExtender();
drg.ID = "drg_1";
drg.DragHandleID = "pnl_1";
drg.TargetControlID = "pnl_2";
Panel p1 = new Panel();
p1.ID = "pnl_1";
Panel p2 = new Panel();
p2.ID = "pnl_2";
Label l1 = new Label();
l1.Text = "First";
TextBox t = new TextBox();
t.Text = "Enter text";
p2.Controls.Add(l1);
p2.Controls.Add(t);
p1.Controls.Add(p2);
Page.Controls.Add(p1);
}
How to I create drag controls inside the panel

How to add WPF page to tabcontrol?

I have this main wpf window
and this WPF page
I need to add this page to tabcontrol in main window
This is my OnRender method
protected override void OnRender(DrawingContext drawingContext)
{
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
pan1.Items.Add(tabitem);
Page1 page1 = new Page1();
tabitem.Content = new Page1();
ISFirstRender = false;
}
base.OnRender(drawingContext);
}
after the application running I faced this exception while selecting the new tab
I need to know how to add wpf page to existing tabcontroll
If you want to add a new Page, as opposed to a UserControl, you can create a new Frame object and place the page in there.
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
Frame tabFrame = new Frame();
Page1 page1 = new Page1();
tabFrame.Content = page1;
tabitem.Content = tabFrame;
pan1.Items.Add(tabitem);
ISFirstRender = false;
}
You can add user controls to the TabControl. So go to the add new items and select the user control and make what you want (like what you have in the page). Then add an instance of that user control to the TabControl.
protected override void OnRender(DrawingContext drawingContext)
{
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
pan1.Items.Add(tabitem);
MyUserControl userControl = new MyUserControl();
tabitem.Content = userControl;
ISFirstRender = false;
}
base.OnRender(drawingContext);
}

Categories