.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> WPF >> Post New QuestionBookmark and Share Subscribe to Forum

wpf document content

Posted By: suwarna     Posted Date: January 11, 2011    Points:2   Category :WPF
hello
i hAVE ONE QUERRY
i want when i adds the controls in document content then these controls are not accessible outside i want accessible outside
my first window code
xaml


<Window xmlns:my="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"

Title="MainWindow" Height="466" Width="446" >
<Grid Height="411" Name="gr1">
<ToolBar Height="28" VerticalAlignment="Top">
<Button Content="New" Click="New_click"/>
<Button Content="Save" Click="Save_click"/>
<Button Content="Delete" Click="Delete_click"/>
<Button Content="Edit" Click="Edit_click"/>

</ToolBar>
<StackPanel >
<TextBox Name="propertyid2" Width="132" Height="38"><Binding ElementName ="numbertxt" Path=" Text"/></TextBox>


</StackPanel>
<ad:DockingManager Name="dockingManager" Margin="0,28,12,12" >

<ad:ResizingPanel Orientation="Vertical">
<ad:DocumentPane Name="mainDocPane" >
<!-- <ad:DocumentContent >
<Grid>
<Label Height="23" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="86" Background="Transparent" Foreground="Wheat" FlowDirection="RightToLeft">PROPERTY ID</Label>
<TextBox Height="21" Margin="157,14,27,0" Name="propertyid" VerticalAlignment="Top" />
<TextBox Height="23" Margin="157,41,27,0" Name="numbertxt" VerticalAlignment="Top" Background="Transparent" Foreground="Wheat" ForceCursor="False" />
<Label Height="23" HorizontalAlignment="Left" Margin="24,41,0,0" Name="label2" VerticalAlignment="Top" Width="66" Foreground="Wheat">NUMBER</Label>
<Label HorizontalAlignment="Left" Margin="21,129,0,116" Name="label3" Width="107" Foreground="Wheat">PROPERTY TYPE</Label>
<Label HorizontalAlignment="Left" Margin="24,70,0,0" Name="label4" Width="66" Height="23" VerticalAlignment="Top" Foreground="Wheat">BUILDING</Label>
<Label HorizontalAlignment="Left" Margin="32,0,0,37" Name="label5" Width="107" Foreground="Wheat" Height="24" VerticalAlignment="Bottom">Area In Square Feet</Label>
<Label Height="21" Margin="12,0,265,89" Name="label6" VerticalAlignment="Bottom" Foreground="Wheat">OTHER INFORMATION</Label>
<TextBox Height="23" Margin="157,0,27,87" Name="info" VerticalAlignment="Bottom" TextChanged="info_TextChanged" />
<TextBox Margin="157,99,27,0" Name="areatxt" Height="24" VerticalAlignment="Top" />
<TextBox Height="23" Margin="157,70,27,0" Name="buildingtxt" VerticalAlignment="Top" />
<ComboBox Margin="157,129,27,116" Name="cmbproptype">
<ComboBoxItem Content="select">
</ComboBoxItem>
<ComboBoxItem Content="rented house">

</ComboBoxItem>
<ComboBoxItem Content="own house">

</ComboBoxItem>
<ComboBoxItem Content="rented commercial"></ComboBoxItem>
<ComboBoxItem Content="own commercial">

</ComboBoxItem>
</ComboBox>
<Label Foreground="Wheat" Height="21" HorizontalAlignment="Left" Margin="12,0,0,62" Name="label7" VerticalAlignment="Bottom" Width="130">OTHER INFORMATION</Label>
<Label Foreground="Wheat" Height="12" HorizontalAlignment="Left" Margin="12,0,0,12" Name="label8" VerticalAlignment="Bottom" Width="130">LAST UPDATE DATE</Label>
<Label Foreground="Wheat" Height="21" HorizontalAlignment="Left" Margin="12,0,0,22" Name="label9" VerticalAlignment="Bottom" Width="130">LAST UPDATED BY</Label>
<TextBox Height="23" Margin="157,0,27,58" Name="datetimetxt" VerticalAlignment="Bottom" />
<TextBox Height="23" Margin="157,0,27,22" Name="lstupdatetxt" VerticalAlignment="Bottom" />
</Grid>
</ad:DocumentContent> -->


</ad:DocumentPane>



<ad:DockablePane>
<ad:DockableContent>
<Grid Height="3" Name="grid1" Width="610" >

<!--<DataGrid x:Name="gridStats" ItemsSource="{Binding Stats}" IsReadOnly="True"/>-->

</Grid>
</ad:DockableContent>

</ad:DockablePane>
</ad:ResizingPanel>
</ad:DockingManager>
</Grid>
</Window>



then source code of first window
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using Microsoft.Win32;
using System.IO;
using AvalonDock;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Data .OleDb ;
using WpfApplication1;


namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

}

int flag = 0;
Int32 propertyid1;
String number1;
String info1;
String building1;
String area1;
String propertytype1;
DateTime date1;
String updateby1;
String cmbopropertyselect;



public void New_click(object sender, RoutedEventArgs e)
{
try{

var doc = new Document();
string title = "Document" + (dockingManager.Documents.Count + 1).ToString();

doc = new Document() { Title = title };
doc.Show(dockingManager);
doc.Activate();
doc. numbertxt.Text = "";

doc. propertyid.Text = "";
doc.numbertxt.Text = "";
doc. buildingtxt.Text = "";
doc.info.Text = "";
doc.lstupdatetxt.Text = "";
doc.datetimetxt.Text = "";
doc.areatxt.Text = "";

// System.Windows.MessageBox.Show(propertyid1.ToString ());
OleDbConnection con = new OleDbConnection();
OleDbDataAdapter ad = new OleDbDataAdapter();
OleDbCommand cmd = new OleDbCommand();
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:/WpfApplication1I/WpfApplicationdemo1/WpfApplicationdemo1/filedb1.mdb");
con.Open();

DateTime d = new DateTime();
String s = d.Date.ToString();


doc.propertyid.IsEnabled = false;
doc.datetimetxt.IsEnabled = false;
doc.datetimetxt.Text = s;

String str = "select * from property";
cmd.CommandText = str;
ad.SelectCommand = cmd;
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:/WpfApplication1I/WpfApplicationdemo1/WpfApplicationdemo1/filedb1.mdb");
cmd.Connection = con;
System.Data.DataSet ds = new System.Data.DataSet();
ad.Fill(ds);
int ind2 = ds.Tables[0].Rows.Count - 1;
int p = Convert.ToInt32(ds.Tables[0].Rows[ind2][0]);
doc.propertyid.Text = (p + 1).ToString();
//ListViewEmployeeDetails.DataContext = ds.Tables[0].DefaultView;

OleDbDataAdapter ad1 = new OleDbDataAdapter();
OleDbCommand cmd1 = new OleDbCommand();
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:/WpfApplication1I/WpfApplicationdemo1/WpfApplicationdemo1/filedb1.mdb");
con.Open();
/// doc.cmbpropertyid.Items.Clear();
String str3 = "select propertyid from property";
cmd.CommandText = str3;
ad1.SelectCommand = cmd1;

cmd1.Connection = con;

System.Data.DataSet ds1 = new System.Data.DataSet();
ad.Fill(ds1);
int i = 0;
/// while (ds.Tables[0].Rows.Count - 1 >= i)
/// {
/// // dr = cmd.ExecuteReader();
/// doc.cmbpropertyid.Items.Add(ds1.Tables[0].Rows[i][0].ToString());
/// i = i + 1;
/// }
propertyid1 = Convert.ToInt32(doc.propertyid.Text);

System.Windows.MessageBox.Show(propertyid1.ToString ());


number1 = doc.numbertxt.Text ;
building1 = doc.buildingtxt.Text;
info1= doc.info.Text;
updateby1= doc.lstupdatetxt.Text;
date1 =Convert .ToDateTime ( doc.datetimetxt.Text);
area1 =( doc.areatxt.Text);

int ind1 = (Convert.ToString(doc.cmbproptype.SelectedItem)).LastIndexOf(':');
int len = (Convert.ToString(doc.cmbproptype.SelectedItem)).Length;

cmbopropertyselect = (Convert.ToString(doc.cmbproptype.SelectedItem)).Substring(ind1 + 1, len - ind1 - 1);
flag = 1;



}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
}

}







private void Save_click(object sender, RoutedEventArgs e)
{
if (flag == 1)
{
try
{


OleDbConnection con = new OleDbConnection();
OleDbDataAdapter ad = new OleDbDataAdapter();
OleDbCommand cmd = new OleDbCommand();
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:/WpfApplication1I/WpfApplicationdemo1/WpfApplicationdemo1/filedb1.mdb");
con.Open();

DateTime d = new DateTime();
String s = d.Date.ToString();
//propertyid.IsEnabled = false;
// datetimetxt.IsEnabled = false;



// System.String str1 = "insert into property values ('" + propertyid.Text + "','+ ddf +','" + buildingtxt.Text + "'," + area + " , '" + info.Text + "','" + d + "','" + lstupdatetxt.Text + "')";
// String str1 = "insert into property(number,building,areainsqrft,propertytype,otherinfo,lastupdateddatetime,lastupdatedby) values ('" + numbertxt.Text + "','" + buildingtxt.Text + "'," + areatxt.Text + ",'" + cmbopropertyselect + "','" + info.Text + "','" + d + "','" + lstupdatetxt.Text + "')";
String str1 = "INSERT INTO property (propertyid, [number], building, areainsqrft, propertytype, otherinfo, lastupdateddatetime, lastupdatedby) VALUES (" + propertyid1 + " ,'" + number1 + "','" + building1 + "'," + area1 + " ,'" + cmbopropertyselect + "','" + info1 + "' , '" + date1 + "','" + updateby1 + "' )";

System.Windows.MessageBox.Show("insert successfully");

// String str = "insert into fileinfo1(ab) values('" + d + "')";


cmd = new OleDbCommand(str1, con);
cmd.ExecuteNonQuery();
/// String str = "select * from property";
/// cmd.CommandText = str;
/// ad.SelectCommand = cmd;
// con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and Settings/windows/My Documents/filedb1.mdb");
/// cmd.Connection = con;
/// DataSet ds = new DataSet();
/// ad.Fill(ds);
/// int ind2;
/// ind2 = ds.Tables[0].Rows.Count - 1;


/// cmbpropertyid.Items.Add(ds.Tables[0].Rows[ind2][0].ToString());
/// ListViewEmployeeDetails.DataContext = ds.Tables[0].DefaultView;


/// con.Close();




}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
}

}

}
private void Edit_click(object sender, RoutedEventArgs e)
{
}
private void Delete_click(object sender, RoutedEventArgs e)
{
}

private void info_TextChanged(object sender, TextChangedEventArgs e)
{

}


}



}



then 2nd window xaml

<ad:DocumentContent x:Class="WpfApplication1.Document"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Width="419" Height="288" Name="doc1">
<Grid Height="268" Width="407">




<Label Height="23" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="86" Background="Transparent" Foreground="Wheat" FlowDirection="RightToLeft" >PROPERTY ID</Label>
<TextBox Height="21" Margin="157,14,27,0" Name="propertyid" VerticalAlignment="Top" Text="{Binding TextContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Height="23" Margin="157,41,27,0" Name="numbertxt" VerticalAlignment="Top" Background="Transparent" Foreground="Wheat" ForceCursor="False" />
<Label Height="23" HorizontalAlignment="Left" Margin="24,41,0,0" Name="label2" VerticalAlignment="Top" Width="66" Foreground="Wheat">NUMBER</Label>
<Label HorizontalAlignment="Left" Margin="21,129,0,116" Name="label3" Width="107" Foreground="Wheat">PROPERTY TYPE</Label>
<Label HorizontalAlignment="Left" Margin="24,70,0,0" Name="label4" Width="66" Height="23" VerticalAlignment="Top" Foreground="Wheat">BUILDING</Label>
<Label HorizontalAlignment="Left" Margin="24,99,0,0" Name="label5" Width="107" Foreground="Wheat" Height="24" VerticalAlignment="Top">Area In Square Feet</Label>
<Label Height="21" Margin="12,0,265,89" Name="label6" VerticalAlignment="Bottom" Foreground="Wheat">OTHER INFORMATION</Label>
<TextBox Height="23" Margin="157,0,27,87" Name="info" VerticalAlignment="Bottom" />
<TextBox Margin="157,99,27,0" Name="areatxt" Height="24" VerticalAlignment="Top" />
<TextBox Height="23" Margin="157,70,27,0" Name="buildingtxt" VerticalAlignment="Top" />
<ComboBox Margin="157,129,27,116" Name="cmbproptype">
<ComboBoxItem Content="select">
</ComboBoxItem>
<ComboBoxItem Content="rented house">

</ComboBoxItem>
<ComboBoxItem Content="own house">

</ComboBoxItem>
<ComboBoxItem Content="rented commercial"></ComboBoxItem>
<ComboBoxItem Content="own commercial">

</ComboBoxItem>
</ComboBox>
<Label Foreground="Wheat" Height="21" HorizontalAlignment="Left" Margin="12,0,0,62" Name="label7" VerticalAlignment="Bottom" Width="130">OTHER INFORMATION</Label>
<Label Foreground="Wheat" Height="12" HorizontalAlignment="Left" Margin="12,0,0,12" Name="label8" VerticalAlignment="Bottom" Width="130">LAST UPDATE DATE</Label>
<Label Foreground="Wheat" Height="21" HorizontalAlignment="Left" Margin="12,0,0,22" Name="label9" VerticalAlignment="Bottom" Width="130">LAST UPDATED BY</Label>
<TextBox Height="23" Margin="157,0,27,58" Name="datetimetxt" VerticalAlignment="Bottom" />
<TextBox Height="23" Margin="157,0,27,22" Name="lstupdatetxt" VerticalAlignment="Bottom" />
</Grid>
</ad:DocumentContent>



and source code of 2nd window


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;

using AvalonDock;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Document.xaml
/// </summary>
public partial class Document : DocumentContent
{
public Document()
{
InitializeComponent();

DataContext = this;




}



new document forn on click new all controls are accessible in

public void new_click () because there is code for create new document but i want when click on save i want to access all control value in public void save_click()
plz help me

Responses
Author: Amit Mehra             
Posted Date: January 30, 2011     Points: 5   

Hi,

Please refer this article..This may help you

http://msdn.microsoft.com/en-us/library/ms748388.aspx

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend