Windows Phone PopUp disable back window - winforms

I have a simple PopUp window in my Windows Phone app, which takes another window as a child:
private static MeterChangeDialog_Popup _instance = null;
private static Popup _meterchangepop;
private MeterChangeDialog_Popup()
{
_meterchangepop = new Popup();
}
public static MeterChangeDialog_Popup GetInstance()
{
if (_instance == null)
{
_instance = new MeterChangeDialog_Popup();
}
return _instance;
}
public void OpenClosePopup()
{
if (_meterchangepop.IsOpen)
{
_meterchangepop.IsOpen = false;
SingletonContainer.GetInstance().MeterChangeCurrentSelected = null;
}
else
{
_meterchangepop.IsOpen = true;
_meterchangepop.Child = new MeterChangePage();
}
}
But while this window is open, I can still do stuff at the window behind it, which I should not be able to do.
Can I somehow disable every window behind the PopUp window ?

Related

How to disable remove button for KryptonPage with context menu close item?

How to block KryptonPage for close and i need to remove button of docking area and context menu option for close
i am using https://github.com/ComponentFactory/Krypton
Visual Studio 2015 Community
Win 10
There are details about my code for clear understanding
Following screenshot is Form designer about using controls
screenshot of Form designer using controls 1
screenshot of Form designer using controls 2
Following screenshot of ruining application
application ruining time for close menu item for block i want it
There are my form code c#
// this is main form code
public partial class frmMain : KryptonForm
{
public frmMain()
{
InitializeComponent();
kryptonPanel1.Dock = DockStyle.Fill;
kryptonDockableWorkspace.Dock = DockStyle.Fill;
kryptonPanel.Dock = DockStyle.Fill;
}
private void Form1_Load(object sender, EventArgs e)
{
KryptonDockingWorkspace w = kryptonDockingManager.ManageWorkspace(kryptonDockableWorkspace);
kryptonDockingManager.ManageControl(kryptonPanel, w);
kryptonDockingManager.ManageFloating(this);
kryptonDockingManager.AddDockspace("Control", DockingEdge.Left, new KryptonPage[] { NewWinTools() });
kryptonDockingManager.AddDockspace("Control", DockingEdge.Bottom, new KryptonPage[] { NewWinTools(), NewWinTools(), NewWinTools(), NewWinTools() , NewWinTools() });
kryptonDockingManager.AddToWorkspace("Workspace", new KryptonPage[] { NewWinControl() });
}
private KryptonPage NewPage(string name, int image, Control content)
{
// Create new page with title and image
KryptonPage p = new KryptonPage();
p.Text = name;
p.TextTitle = name;
p.TextDescription = name;
p.ImageSmall = imageListSmall.Images[image];
// Add the control for display inside the page
content.Dock = DockStyle.Fill;
p.Controls.Add(content);
return p;
}
private KryptonPage NewWinControl()
{
UserControl1 br = new UserControl1();
KryptonPage page = NewPage("New Tab", 0, br);
page.ClearFlags(KryptonPageFlags.DockingAllowAutoHidden | KryptonPageFlags.DockingAllowDocked);
return page;
}
private KryptonPage NewWinTools()
{
UserControl1 br = new UserControl1();
KryptonPage page = NewPage("Tools 1 ", 2, br);
page.ClearFlags( KryptonPageFlags.DockingAllowClose);
return page;
}
}
please help for block close KryptonPage
I have just come across the same issue. I can see that this question was answered here
It looks like there is no way of actually removing the close button but you can intercept it and then ignore the event.
In the interest of completeness, this is the code you need to write:
private void CreateDockWorkspace()
{
KryptonDockingWorkspace w = kryptonDockingManager.ManageWorkspace("Workspace", kryptonDockableWorkspace);
kryptonDockingManager.ManageControl("Control", kryptonPanel, w);
kryptonDockingManager.ManageFloating("Floating", this);
kryptonDockingManager.AddToWorkspace("Workspace", new KryptonPage[] {
NewPage("Overview"),
NewPage("Main"),
NewPage("Report"),
});
// This is where you wire up the CloseAction event handler
var workspace = kryptonDockingManager.CellsWorkspace.FirstOrDefault();
workspace.CloseAction += HandleTabCloseAction;
}
private void HandleTabCloseAction(object sender, CloseActionEventArgs e)
{
// This event handler ignores the action
e.Action = CloseButtonAction.None;
}
private KryptonPage NewPage(string name)
{
var p = new KryptonPage();
p.Text = name;
p.TextTitle = name;
p.TextDescription = name;
content.Dock = DockStyle.Fill;
p.Controls.Add(content);
return p;
}

MVVM Open a view from Mainview with command

I'm trying to open a view from my mainview in a button click command, I just need to know what i have to replace in my method GoToNewPage()
private DelegateCommand newPageCommand;
public ICommand NewPage
{
get
{
if (newPageCommand == null)
{
newPageCommand = new DelegateCommand(GoToNewPage);
}
return newPageCommand;
}
}
private void GoToNewPage()
{
//What i have to write there?
}
private void GoToNewPage()
{
var window = new ViewClassName();
window.Show();
}

Show Splash Screen & Progress Bar with Percentage using MVVM & WPF

I need to show Splash Screen with Image & progress bar.
In my application start up i have the code as below to show the main window.
SplashScreenWindowViewModel vm = new SplashScreenWindowViewModel();
AutoResetEvent ev = new AutoResetEvent(false);
Thread uiThread = new Thread(() =>
{
vm.Dispatcher = Dispatcher.CurrentDispatcher;
ev.Set();
Dispatcher.CurrentDispatcher.BeginInvoke((Action)delegate()
{
SplashScreenWindow splashScreenWindow = new SplashScreenWindow();
splashScreenWindow = new SplashScreenWindow();
splashScreenWindow.Show();
splashScreenWindow.DataContext = vm;
vm.InstigateWorkCommand.Execute(null);
});
Dispatcher.Run();
});
uiThread.SetApartmentState(ApartmentState.STA);
uiThread.IsBackground = true;
uiThread.Start();
ev.WaitOne();
In my main viewmodel i have code as below
class MainviewModel : viewmodelbase
{
rivate string _message;
private object content;
private readonly BackgroundWorker worker;
private readonly ICommand instigateWorkCommand;
public SplashScreenWindowViewModel()
{
this.instigateWorkCommand = new
RelayCommand(() => this.worker.RunWorkerAsync(), () => !this.worker.IsBusy);
this.worker = new BackgroundWorker { WorkerReportsProgress = true };
this.worker.DoWork += this.DoWork;
this.worker.ProgressChanged += this.ProgressChanged;
_message = "0 % completed";
}
public ICommand InstigateWorkCommand
{
get { return this.instigateWorkCommand; }
}
private double _currentProgress;
public double CurrentProgress
{
get { return this._currentProgress; }
set
{
if (this._currentProgress != value)
{
this._currentProgress = value;
RaisePropertyChanged("CurrentProgress");
}
}
}
private int _progressMax;
public int ProgressMax
{
get { return this._progressMax; }
set
{
if(this._progressMax != value)
{
this._progressMax = value;
RaisePropertyChanged("ProgressMax");
}
}
}
private void ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.CurrentProgress = e.ProgressPercentage;
}
private void DoWork(object sender, DoWorkEventArgs e)
{
// calling my long running operation
DAL.dotimeconsumingcode();
worker.ReportProgress((int)e.argument);
}
public string Message
{
get
{
return _message;
}
set
{
if (Message == value) return;
_message = value;
RaisePropertyChanged("Message");
}
}
public object Content
{
get
{
return content;
}
set
{
if (Content == value) return;
content = value;
RaisePropertyChanged("Content");
}
}
public Dispatcher Dispatcher
{
get;
set;
}
}
MY UI has one user control with progress bar and one splash main window.
when my long running operation is completed , my Main window(main application) is opened.
//User Control
<ProgressBar Height="27" Value="{Binding CurrentProgress, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Margin="53,162,57,0" Name="progressBar" Grid.Row="1"
Maximum="{Binding Path=ProgressMax, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ProgressVisibility}" />
//SplashWindow
<localView:usercontrol/>
My Problem is
ProgressChangedevent is not firing and % completion is not showing up in the text block either. Please help
You have not registered a complete handler and you are not calling progress properly.
This sample from MSDN covers it all.
BackGroundWorker

How do I provide designer support to a TabControl residing in a UserControl, so that I can drag/drop controls onto tab pages?

I have a user control, which contains both a Panel and a TabControl. I enabled design-time support for both. I can drag/drop controls from the toolbox onto the Panel control that resides within the user control. I can also add and remove tab pages via the designer on the TabControl. However, I am not able to drag/drop any controls onto the tab pages themselves.
Below is the code generated source code for my user control:
partial class TestUserControl
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.tabControl = new System.Windows.Forms.TabControl();
this.contentPanel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// tabControl
//
this.tabControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl.Location = new System.Drawing.Point(0, 0);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(306, 118);
this.tabControl.TabIndex = 0;
//
// contentPanel
//
this.contentPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.contentPanel.Location = new System.Drawing.Point(0, 118);
this.contentPanel.Name = "contentPanel";
this.contentPanel.Size = new System.Drawing.Size(306, 73);
this.contentPanel.TabIndex = 0;
//
// TestUserControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tabControl);
this.Controls.Add(this.contentPanel);
this.Name = "TestUserControl";
this.Size = new System.Drawing.Size(306, 191);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.Panel contentPanel;
}
Below is the source code I added to enable design-time support:
[Designer(typeof(TestUserControlDesigner))]
public partial class TestUserControl : UserControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TabControl TabControl
{
get { return this.tabControl; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel ContentPanel
{
get { return this.contentPanel; }
}
public TestUserControl()
{
InitializeComponent();
}
}
internal class TestUserControlDesigner : ParentControlDesigner
{
public override void Initialize(System.ComponentModel.IComponent component)
{
base.Initialize(component);
EnableDesignMode(
(this.Control as TestUserControl).TabControl, "TabControl");
EnableDesignMode(
(this.Control as TestUserControl).ContentPanel, "ContentPanel");
}
}
What do I need to do, so that I can drag/drop controls onto the tab pages of the TabControl?
You have to enable design mode on the existing tab pages as well:
internal class TestUserControlDesigner : ParentControlDesigner {
public override void Initialize(System.ComponentModel.IComponent component) {
base.Initialize(component);
var ctl = (this.Control as TestUserControl).TabControl as TabControl;
EnableDesignMode(ctl, "TabControl");
foreach (TabPage page in ctl.TabPages) EnableDesignMode(page, page.Name);
EnableDesignMode((this.Control as TestUserControl).ContentPanel, "ContentPanel");
}
}

WPF closing child- closes parent-window

i have the pretty same sample as mentioned here.
Fast concluded: MainWindow closes when the last childwindow is closed.
My Problem: I couldn't solve my problems with the described solutions. I can't produce a program where it als takes place. Only in one of my bigger progs. Maybe someone has an idea or knows any further steps.
Thanks for reading - Thomas
As requested here's a bit of code:
This is the part in the MainWindow:
bool editAfterSearch = false;
Movie selectedMovie = (Movie)this.listView.SelectedItem;
Movie backup = (Movie)selectedMovie.Clone();
if (new OnlineSearchWindow().EditMovieViaOnlineSearch(ref selectedMovie, out editAfterSearch))
{
this.coverFlow.Update(selectedMovie);
}
And that's the part of the ChildWindow:
public bool EditMovieViaOnlineSearch(ref Movie preset, out bool editAfter)
{
this.exitWithOk = false;
this.editMovieAfterSearch = false;
this.tbx_SearchTerm.Text = preset.Title;
this.linkedMovie = preset;
this.ShowDialog();
editAfter = editMovieAfterSearch;
if (this.exitWithOk)
{
this.linkedMovie.CloneOnlineInformation(ref preset);
preset.Bitmap = this.linkedMovie.Bitmap;
return true;
}
else
{
return false;
}
}
Try playing with the ShutDownMode property of your App.xaml.cs. The 3 values are OnMainWindowClose, OnLastWindowClose, and OnExplicitShutdown, and the default is OnLastWindowClose
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose;
}
}
The below code worked for me.
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBoxResult.No == (MessageBox.Show("Are you sure you want to close this?.", "ProjectName", MessageBoxButton.YesNo)))
{
e.Cancel = true;
foreach (var item in Application.Current.Windows)
{
Window window = item as Window;
if (window.Title == "PopUpWindowName")
{
window.Topmost = true;
break;
}
}
return;
}
else
{
base.OnClosed(e);
Application.Current.Shutdown();
}
}
you can try setting the child window's allowShutDown to false and then show the mainwindow. I'm assuming you will start with mainwindow's visibility set to hidden.
Application.Current.MainWindow.Visibility = System.Windows.Visibility.Visible;
this.allowShutDown = false;
The allowShutDown will be your own property which u can set to enable you have to handle the closing event.

Resources