|
Jammer wrote: Navigator.ApplicationViewStatusChanged += new Navigator.ApplicationViewChanged(sender, ApplicationViewEventArgs e);
Will need to go in the class where your usercontol is instanciated, not in the Navigator class itself, so the containing class can listen for its events.
Edit: It will probably look something like this:
navigator1.ApplicationViewStatusChanged += new Navigator.ApplicationViewChanged(navigator1_ApplicationViewStatusChanged);
void navigator1_ApplicationViewStatusChanged(object sender, Navigator.ApplicationViewEventArgs e)
{
}
Dave
|
|
|
|
|
oh btw the user control isn't created using anything like navigator navigator1 = new navigator(); as that is in XAML ... it just gets launched at runtime in the mainwindow() ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
it makes no difference, just refer to the object by the name you gave it in the xaml. Intellisense should take care of the rest for you.
Dave
|
|
|
|
|
Have tried that and its not showing me anything called Navigator1 (i've tried giving it just Name="Navigator1" and x:Name="Navigator1")
Man this is starting to hurt my head.
I know I'm being a pain but can you just review this for me:
public SampleSortMainWindow()
{
SetSystemConstants.SetConstants();
InitializeComponent();
Navigator1.ApplicationViewStatusChanged += new Navigator.ApplicationViewChanged(Navigator1_ApplicationViewStatusChanged);
lyrBrowserView.Visibility = Visibility.Visible;
lyrDatabaseView.Visibility = Visibility.Hidden;
}
the XAML is:
<UserControl<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
xmlns:d="http://schemas.microsoft.com/expression/blend/2006"<br />
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"<br />
mc:Ignorable="d"<br />
Name="Navigator1"<br />
x:Class="SampleSort.Presentation.Navigator"<br />
Height="32" Width="64" ClipToBounds="True"><br />
<Grid>
And this is in the Navigator:
public sealed class ApplicationViewEventArgs : EventArgs
{
private Enums.ApplicationView _applicationView;
public Enums.ApplicationView ApplicationViewStatus
{
get
{
return _applicationView;
}
}
public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus) : base()
{
_applicationView = ApplicationViewStatus;
}
}
public partial class Navigator : UserControl
{
public delegate void ApplicationViewChanged(object sender, ApplicationViewEventArgs e);
public event ApplicationViewChanged ApplicationViewStatusChanged;
public Navigator()
{
InitializeComponent();
}
private void btnBrowseView_Click(object sender, RoutedEventArgs e)
{
if (ApplicationViewStatusChanged != null)
ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.BrowserView));
}
private void btnDatabaseView_Click(object sender, RoutedEventArgs e)
{
if (ApplicationViewStatusChanged != null)
ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.DataBaseView));
}
}
The current error is Navigator1 does not exist in the current context. I added a breakpoint and looked at how things are initialised and the Navigator1 is the first thing to be initialized after the Main screen initialize so it should be able to find Navigator1 shouldn't it?
Thanks for the help Dave.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
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
|
|
|
|