I have used the brilliant article from CodeProject.
http://www.codeproject.com/Articles/856020/Draw-Behind-Desktop-Icons-in-Windows
This project running fine for me on windows 8.1
The example using Forms. Now I'll change the Form
to WPF-Window (using Visualstudio 2015 with .net 4.5.2).
// The WPF-Window for infos behind the icon
public partial class InfoBehindIcon : Window
{
public InfoBehindIcon()
{
InitializeComponent();
// in .xaml: the decoration switched off
}
}
// The MainWindow - class
....
private HInfoBehindIcon.InfoBehindIcon infoBehindIcon = new HInfoBehindIcon.InfoBehindIcon();
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject example starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
}
private void iniDesktopHandlerWPF()
{
... Code from CodeProject example
if(dc != IntPtr.Zero)
{
// here I change the Form to WPF-Window
infoBehindIcon.Loaded += infoBehindIcon_EventWPF;
}
}
private void infoBehindIcon_EventWPF(object sender, EventArgs e)
{
infoBehindIcon.Topmost = false;
InfoPanel.HW32.SetParent(new WindowInteropHelper(infoBehindIcon).Handle, workerw);
}
The version using Forms running without problems.
When I am trying this with changes to WPF the second window is starting but
it is not running between desktop and icons.
Is there a way to solve this?
Or it is better way to use furthermore the Form?
(sorry I am a newbee in C#)
The problem was too simple and easy. I solved this
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
}
with
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
infoBehindIcon.Show();
}
Now it works fine for me. I did not see it...... ;)
Related
I follows samples code provided in https://github.com/PrismLibrary/Prism-Samples-Wpf/blob/master/17-BasicRegionNavigation
I want to achieve the following result when I run the application (without explicitly clicking Navigate to View A). Does anyone know how to do it?
I have tried adding Navigate("ViewA"); after this line. However, I cannot get the desired outcome. Is it because the module hasn't been initialized?
Thanks.
did you add your module to the modulecatalog using override method ConfigureModuleCatalog? take a look at here
Eventually I solve by adding the following code in MainWindow.xaml.cs
public partial class MainWindow
{
IRegionManager _regionManager;
public MainWindow()
{
InitializeComponent();
_regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
RegionManager.SetRegionManager(ContentRegion, _regionManager);
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
_regionManager.RequestNavigate("ContentRegion", "ViewA");
}
}
Get idea from: https://github.com/MahApps/MahApps.Metro/issues/1020#issuecomment-44779574
I'm kinda late to the party here, but I also stumbled over the question of how to navigate to a default view during the applications startup.
I found two ways:
1. App decides the default view
This can be solved in the CreateShell()-override in the App-Class.
This is my CreateShell-Method:
/// <inheritdoc />
protected override Window CreateShell()
{
var window = this.Container.Resolve<MainWindow>();
window.Loaded += (sender, args) =>
{
var manager = this.Container.Resolve<IRegionManager>();
manager.RequestNavigate("ContentRegion", "ViewA");
};
return window;
}
2. ViewModel decides the default view
Add a constructor to MainWindowViewModel that looks like this:
public MainWindowViewModel(IRegionManager regionManager)
{
regionManager.RegisterViewWithRegion("ContentRegion", "ViewA");
}
I have a winform app, I completed with business model and update function. But when I learn about security .Net, I found that almost impossible to anti crack/hacking with obfuscation.
So I want move 99.99% source code to cloud. But I've not found any doc that useful for making it.
Can I do my idea as below:
using ....;
namespace myApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public GetSourceClass()
{
// Here i want get all source code, include all class and all
// variables from server.Is it possible?
}
private void Form1_Load(object sender, EventArgs e)
{
GetSourceClass();
}
I am developing an application in WPF. I need to load an instance of the Window class (which I call Win1 here) with which a form is filled. Then, when the Submit button is clicked, Win1 closes and only then can a new Win2 window be loaded (another class, also inherited from Window). The problem is that both of them open and I can not synchronize the data obtained from the first Win1 and pass them to the second Win2. I'm just messing up.
Someone can give me a generic idea indicating the tools and the pattern I need to do the above. For the specifications given to me, it is necessary that Win2 appears only after Win1 has finished its work.
Even though the application is more complex than I described it now, I would like to post some code, but I manage to confuse the ideas of who is reading me, so I tell you that at the moment I'm managing the windows inside the constructor of App.cs, while MainWindow.cs corresponds to Win2 and I created a new class to implement Win1.
public partial class App : Application
{
// Params...
public App()
{
Client = LoadNetwork();
User = LoadUser(Client); // Shows Win1
Games = LoadMinigames();
mainWindow = new MainWindow(User, Games);
Application.Current.MainWindow = mainWindow; // On XAML default is Hidden
mainWindow.Show(); // Shows Win2
}
// Other methods...
}
The biggest problem for me is to pass User data to MainWindow and I do not have many ideas on how to deal with this case.
Update
public partial class MainWindow : Window
{
public UserLoading ul;
public UserRegistering ur;
public User.UserProfile User;
private List<Game.Game> Games;
public Label Username;
public MainWindow(User.UserProfile user, List<Game.Game> games)
{
User = new UserProfile();
InitializeComponent();
User = user;
Games = games;
Username.Content = User.Username;
DrawList(Games);
}
//...
}
I realize I have explained myself a bit 'badly rereading my question several times. So I update it trying to be clearer by reporting here my answer to one of the comments.
The UserLoad method is not blocking, because inside it are instantiated classes that inherit Window (other windows for login and registration in other words) then the flow of execution proceeds and instantiates the MainWindow where naturally the argument "user" will result null because the forms have not been filled yet. I realize now that perhaps I had explained myself badly. The call of Win1 is not blocking and I would like it to return only when the user data is ready to be passed as an argument to Win2.
I have done this in the past. here is my solution:
Set Your Launch Window to Win1. Let It launch. Create a Static Method in App.cs to launch Win2. When Win1 is ok to shut down and you want Win2 to open call App.ShowMainWindow(this) from within Win1.
App.cs
public partial class App : Application
{
static internal void ShowWin2(Win1 win1)
{
Win2 win2 = new Win2();
// Copy Win1 stuff to Win2 here
Application.Current.MainWindow = win2;
win2.Show();
}
}
Win1
public partial class Win1 : Window
{
public Win1()
{
InitializeComponent();
}
private void CloseAndLaunchWin2()
{
App.ShowWin2(this);
this.Close();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CloseAndLaunchWin2();
}
}
As User Nawed mentioned, you should read into MVVM. Syncing can be achieved by using the same model for two different views.
You could do something like this.
var sharedContext = new MyViewModel();
var viewOne = new MyWindow();
var viewTwo = new MyUserControl();
viewOne.DataContext = viewTwo.DataContext = sharedContext;
I have a WPF Menu application wich calls a WPF User Control dll and the dll window is not showing. The dll does not require parameters and its window have only one button. I added a MessageBox to the dll code to check if it is being loaded and it does, but the window does not show.
I'm using VS 2015. The dll project named Empresa.Reg was created using C# Windows Classic Desktop WPF User Control (There is no C# Windows WPF User Control selection), it is referenced in the Menu project and its ouput is Class Library. Menu project named MenuDePruebas Ouput is Windows Application. Any help would be appreciated.
This is the Menu exe code:
....
using System.Windows;
using Empresa.Reg;
namespace MenuDePruebas
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void BtnRegEmpresa_Click(object sender, RoutedEventArgs e)
{
UserControl1 algo = new UserControl1();
}
}
}
And this is the WPF User Control dll code:
....
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Empresa.Reg
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
MessageBox.Show("Testing"); // This line works as expected
}
private void button_Click(object sender, RoutedEventArgs e)
{
}
}
}
I think I've found a solution creating a new window for the dll user control in the menu exe as follows, something I thought was an automatic thing. If there is a better solution I appreciate letting me know. Thanks.
private void BtnRegEmpresa_Click(object sender, RoutedEventArgs e)
{
Window UserControlNewWindow = new Window
{
Title = "Some Title", Content = new UserControl1()
};
UserControlNewWindow.ShowDialog();
}
One simple way:
in ur xaml of the Window add a ContentControl
as u click the menu put corresponding usercontrol in the contentcontrol
<ContentControl x:Name="CntUsercontrol"/>
In code behind
CntUserControl.Content = new UserControl();
If you use MVVM the you can switch the views based on the viewmodel using a DataTemplate.
Hope this helps
I'm not able to see my Window in the plug in area. I know that some code must be added in the Integrate section. However i don't know which.
public void Integrate() { }
public void IntegratePresentation() {}
How can I make it visible? Is it really possible?, if not How can I display a window in Petrel?
You should add your window to the system so that Petrel displays it when requested to.
Your window class should be a ToggleWindow:
public class MyWindow : ToggleWindow{
...
}
Add a menu through which you can ask Petrel to create and open your window in the Windows area:
public void IntegratePresentation()
{
WellKnownMenus.Window.AddTool(
new PetrelButtonTool("&My Window",
PetrelImages.Editor,
(sender, e) => PetrelProject
.ToggleWindows
.Add(new MyWindow())));
}
I hope this helps.