How to open closed TabItems on button click using MVVM & WPF? - c#

I'm using DevExpress controls. I have a DocumentLayoutManager in that I have DocumentGroup.
For Example:
<dxdo:DocumentLayoutManager>
<dxdo:DocumentGroup x:Name="dcGroup"/>
</dxdo:DocumentLayoutManager>
Also I have Buttons. For Example:
<Button x:Name="btn1" Command{Binding btn1Click}/>
<Button x:Name="btn2" Command{Binding btn2Click}/>
I'm loading Tabs in DocumentGroup from ViewModel on respective button click(Ex: btn1click = TabItem1 & btn2click = TabItem2). Now if user clicks btn1 & btn2 then both Tabs get open, now my question is if user closes any of the tabItem which is already open and then clicks on the button again then i need to show that tab in DocumentGroup again.

Generally when programming, we try to make repeatable functions. You said:
Now if user clicks btn1 & btn2 then both Tabs get open, now my question is if user closes any of the tabItem which is already open and then clicks on the button again then i need to show that tab in DocumentGroup again
Your function that opens the TabItems should also be repeatable. I'm guessing that you have some sort of method that you called to get and/or set the data, and generally add the TabItem. If the user closes a TabItem and then wants to reopen it, you should aim to call the same method again. If there is a particular problem or reason why you can't do that, then fix that problem, because this scenario is what you should be aiming for.

Related

Keep toggle button from one form ON when switching to a different form

So basically, I have a C# winform and it has multiple pages (which are different forms) when going to one page to another it closes the previous form/page. However, I have a “Settings” page and on that form I have a toggle button. That toggle button changes the text of a label on form1. If I force the form the open while the “settings” form is open, the text changes. However, I do NOT want that form to actually open I just want the text to change but when I take out the form1.Show(); , and just toggle the button off and switch back to form1 the text is the original and when switching back to settings, the toggle button has re-enabled itself. I cannot figure this out.

Trigger a button click that is inside a user control from a windows form in c#

I'm developing an application in c# .net framework and I have a user control not developed by me that contains various buttons that when clicked show different kind of data and statistics (let's call it ucDataShow).
Such user control is in a different tab with respect to the main tab of my program (i'm talking about TabControl)
I'd like to create a button in my application that when clicked changes tab and shows the appropriate kind of data by simulating the click of the appropriate button of ucDataShow
Is there a way to do so?
you can change tabpage of tabcontrol like this:
tabControl1.SelectedTab = tabControl1.TabPages[n];
but i think it is not possible to raise click event of button which is on ucDataShow control.

Make a cutom popup with darkened background in uwp with XAML c#

I have made a few buttons for my admin page, for example-delete user, change info etc.. I want the window to darken once I click on one of the buttons, and then I want my own custom popup to appear(it will act like a small window), where I could, for example, enter values-the name of the user I want to delete for instance and then if I want to exit the popup, I will just have to click on the darkened background.
Technically, I could just achieve the same thing by making multiple windows and referencing to them on the click of each button, however, I think it will look unprofessional.
Does anyone know how can I achieve what I have just written? My biggest problem is with even creating a custom popup because so far I have only used the default dialog box.
I will be very thankful for any help.
I want my own custom popup to appear(it will act like a small window)
Did you tried to use ContentDialog Class ?
if I want to exit the popup, I will just have to click on the darkened background.
Because of ContentDialogs are Modal dialog to achieve this you should use PopUp Class instead of ContentDialog.
Something like below source for XAML page then set its IsOpen=true; in code behind to show popup to user:
<Popup x:Name="popupDeleteUser"
IsLightDismissEnabled="True"
IsOpen="false">
<Grid>
Put your controls here
</Grid>
</Popup>
I want the window to darken once I click on one of the buttons
you can use Blur animation

How to load a WPF window with values last entered?

I have 2 WPF windows. Both the windows have textboxes and combo boxes. Upon entering data into Window1, the user presses a "Next" button and Window2 is loaded. Window2 has a "Back" button which will reload Window1 incase the user wants to change some values. Since it is the same session, I want the last entered values in window1 to appear when the "Back" button in Window2 is pressed. How should I go about doing it in C# or XAML?
you have to take one property in window 1 like
public string ChangeValue { get; set; }
when you press back buttion at that time you can set the property value using instance of window 1
instanceofWindow1.ChangeValue="Value";
Each window should have its own ViewModel. These contains the values you type in the windows. If you click next (and destroy the first window) the you should implement some kind of save method (ICommand that is invoked when clicking on Next) that saves the current state of the ViewModel to a model class (or a database or a text file ...). When you click back you have to reload the model, connect it with the ViewModel and show the Window1.
It seams you are not familiar with WPF, maybe the links from another answer might help you to get started: https://stackoverflow.com/a/2034333/1015350
Furthermore you should get into the topics:
MVVM
ICommands
Databinding
Rule of thumb: Your code behind file should contain nothing. This is all done by databinding.

ToolStripButton have different behavior on showing Modal Less Dialog

I have a main window and a toolstrip on it with different command buttons. In these commands, I've a 'Print' button too (See Below). When I click on 'Print' button , I need to show sub-form as Modal Less Dialog. Because, I've few option on sub-form. If user select them then he/she can interact with Main Form too.
Meanwhile, on show() method I disable all controls on Main Form (see below) as it will be done if I use ShowDialog() method to show sub-form. When I click the Print Button, it's color changed which shows it is focused/selected.
On click sub-form is show like below pic.
Logically, it should return to previous mode when I close sub-form. But, even sub-form is showing... that 'Print' button on Main-Form is still focused/selected. When I close the sub-form, that 'Print' Button still focused/selected like below.
What Event/ Property needs to be changed to make this 'Print' Button to show like as it is in initial state.
I've tried Invalidate(), change BackColor but didn't meet the requirement yet. Any Guidelines ?
Set the CheckOnClick property of your button to false if you don't want it to appear "selected" at all, otherwise toggle the CheckState property on the button when the subform is closed.
Well, Selected Property in ToolStripButton is read only. Anyone, needs to clear the selection of toolstrip buttons can use below method which is invoked via reflections.
MethodInfo method = typeof(ToolStrip).GetMethod("ClearAllSelections", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(yourToolStripName, null);
This comes from : How to Deselect ToolStripItems
Happy Programming.

Categories