|
Done a very simple example that you may be able to learn from so you can fix your problem.
I created a default WPF app (WpfApplication1) then created a user control (UserControl1).
In UserControl1 (in the namespace but outside the class) I created a delegate
public delegate void UserControlDelegate(object sender, EventArgs e);
and (inside the class) an event public event UserControlDelegate UserControlEvent;
then added a public property that when set raises the event with this:
if (null != UserControlEvent)
UserControlEvent(this, EventArgs.Empty);
Then I added this to Window1.xaml xmlns:UserControlNamespace="clr-namespace:WpfApplication1"
and then in the Grid block
<UserControlNamespace:UserControl1 x:Name="MyUsercontrol" Width="100" Height="100"></UserControlNamespace:UserControl1>
then changed the Window1 class in Window1.xaml.cs to
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
MyUsercontrol.UserControlEvent += new UserControlDelegate(MyUsercontrol_UserControlEvent);
}
void MyUsercontrol_UserControlEvent(object sender, EventArgs e)
{
Console.WriteLine("Event Raised");
}
}
This is not exactly how I'd do it in production (I'd use protected virtual methods to raise the event etc, etc... ) but it should get you started.
Dave
|
|
|
|
|
Wow, thanks for this dave ... much appreciated. Will have a look at this in comparison to my problem.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Oh man ... what a doughnut I have been ...
Basically, the whole deal was that I was giving the Navigator an x:Name="" in the Navigator xaml NOT the mainwindow.xaml file ... its all working as expected now ...
Thank you Dave!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
No problem
Dave
|
|
|
|
|
Hi Jammer,
I have some suggestions and comments:
1.
if a subject is not clear to you, my first advice is to read the documentation (use Google,
and look for links with MSDN or MSDN2 in them)
2.
since documentation often is rather short and lacks contextual information, I always advice
to have a good tutorial at hand, and read the relevant chapter.
3.
I did a short article on events and delegates; it does not explain all of it, it does providce
some examples and gives you some hints.
4.
When you have compile errors, look at them carefully and solve them; pay attention especially
to the first error message, and try to get rid of that one first. Then recurse until none are
left. Don't start adding unrelated code (and more errors) until you have fixed the ones you
already have.
5.
Also pay attention to the compiler warnings; a good programmer knows every warning is
a candidate for a run-time problem later on, so get rid of them too.
6.
We are not in the spoon feeding business. As a programmer you are supposed to search, read around,
try, correct and test; and when stuck, to ask specific questions while providing clear information.
"the compiler is throwing loads of errors" is not informative.
7.
keep it up!
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
point taken ... sorry. I've been reading and trying various things but i've just been going round in circles so far and its just getting to me a bit now.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi,
How does one take data from a datagrid and display it in an Excel spreadsheet? I have got data in a datagrid and would like to import it to a spreadsheet. Please help.
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
|
Hi,
Thanks for the reply, but I am doing a Windows application. So how different is the code from this article to the one of a Windows application? Or is there an article that demonstrates how to import from a (Windows application) to an Excel spreadsheet?
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
Walaza wrote: So how different is the code from this article to the one of a Windows application
since the control is the same, the code shouldnt differ a lot.
try out and ask again, if you get stuck.
|
|
|
|
|
What do I replace the ff with:
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.txt"); etc
because 'Response.' is not known in a Windows application.
Mvelo Walaza
Developer
Telkom SA
|
|
|
|
|
I need to capture mouse right click in WinForms DataGridView column header. I tried
class MyDataGridView: DataGridView {
protected override void
OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) {
....
OnColumnHeaderMouseClick occurs when header is right or left-clicked by
mouse. DataGridViewCellMouseEventArgs does not provide
information which mouse button is pressed.
How to find when mouse is right-clicked in column header ?
Andrus.
Andrus
|
|
|
|
|
HI
i write two application with C#. at now i want to create an interaction between them.
what is best way to do this (create interaction between 2 application) ?
can we do this with interfaces ?
|
|
|
|
|
Saeed.394,
What do you mean by "interaction"? Do you want to just call methods in the other app? or send data to it?
Regards,
Gareth.
|
|
|
|
|
i m having a lot of forms(with mdi parent)...on main form which is called on load of mdi form which displays a list of users.. and in another form we can add/modify th user...so i want to refresh the main form..i did main mn=new main();..and then call the function mn.load()...but because its creating a new instance...so the function is not working....so i want to pass the same object to another form ....how can i do that please help me..
|
|
|
|
|
|
Is There A C# Code That Will Allow Me To Restart The PC Into Safemode With Network Access?
|
|
|
|
|
Import ExitWindowsEx() from user32.dll and use it to restart windows. I am not sure if this API would let you restart in safe mode with network access. But probably you could edit the boo.ini file from your program and get that too done.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Thanks For The Fast Reply! Will Give It A Try!!!
|
|
|
|
|
when i try to open a report in my application on a test machine it gives me this error
-------------------------------------------------------------------
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WinForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.ReportViewer.WinForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
--------------------------------------------------------------------
is there any runtime requirement for crystal report?
does merge modules require to have a deployment project?
|
|
|
|
|
can anyoner plz. help me out in writing a code in c# for
Sending SMSs from your Microsoft .NET Compact Framework-based Applications
regards
|
|
|
|
|
Dear Friends
I am developing application for a browsing center,
I want to restrict users to access some websites and some File formats to Download.
Now I say
http://www.java2s.com/Code/CSharp/Network/ImplementsamultithreadedWebproxyserver.htm
Multithreaded Web proxy server code
And this code is gives me an error as "The operation has timed out" error at System.Net.HttpWebRequest.GetResponse()
1. What is the problem?
2. I get URL name in this code, and I can filter the web sites here. Now how can I filter the creation formats to download?
Please help me.
By
Joe
|
|
|
|
|
Dear Frieds
i have done a sample application for WMI Scheduling, and i could schedule jobs using it.
my problem is i schedule the task to work on every day but that task is assigned for saturday
Hear is my Sample Code.
ManagementClass classInstance = new ManagementClass("root\\CIMV2","Win32_ScheduledJob", null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
inParams["StartTime"] = "********113000.000000+330";
//YYYYMMDDHHMMSS.MMMMMM(+–)OOO
ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
ManagementClass classInstance = new ManagementClass("root\\CIMV2","Win32_ScheduledJob", null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
inParams["StartTime"] = "********113000.000000+330";
//YYYYMMDDHHMMSS.MMMMMM(+–)OOO
ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
Any Problem in my Code.
Please help me.
With Love
joe
|
|
|
|
|
is there any way to hide those button???
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
maybe there is a way, but hiding up and down buttons of a control which mainly differs from a textbox by additional up and down buttons doesnt sound like a very good idea.
you can use a textbox and add a validator.
|
|
|
|