Keep window on top WPF - c#

I have problem to keep Window on TOP ? I work with MVVM WPF
I have this code in ConfigRole Model:
if (!System.Windows.Application.Current.Windows.OfType<ConfigRole>().Any())
{
ConfigRoleModel configRoleModel = new ConfigRoleModel();
ConfigRole winconfigRole = new ConfigRole();
winconfigRole.DataContext = configRoleModel;
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}
Here the new Window is Correct, it is on TOP,
but after that, I want to show other Window on TOP from ConfigRoleModel ,
this is code ConfigRoleModel :
if (!System.Windows.Application.Current.Windows.OfType<ButtonListView>().Any())
{
ButtonListViewModel buttonListViewModel = new ButtonListViewModel();
ButtonListView winconfigRole = new ButtonListView();
winconfigRole.DataContext = buttonListViewModel;
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}
So ,here I don't have this new Window on TOP!
I don't understand! it is the same code like the first ..
I try also with winconfigRole.ShowDialog();
and `Window.activate()
And the same Problem!
How can I fix it?
Thanks

Set the Owner property the ConfigRole to the MainWindow (or whatever window you open it from) and the Owner property of ButtonListView to the ConfigRole window:
if (!System.Windows.Application.Current.Windows.OfType<ButtonListView>().Any())
{
ButtonListViewModel buttonListViewModel = new ButtonListViewModel();
ButtonListView winconfigRole = new ButtonListView();
winconfigRole.DataContext = buttonListViewModel;
winconfigRole.Owner = System.Windows.Application.Current.Windows.OfType<ConfigRole>().FirstOrDefault(); //<--
winconfigRole.Show();
winconfigRole.Topmost = true;
winconfigRole.Focus();
}

Related

Gtk# application is not rendering TreeView Properly

I am trying to develop a gtk application on mac using gtk#. I created a tree view just like in the tutorial but the arrows are not rendering properly as seem below, there are no arrows. I can click to open and close but the actual arrows aren't working.
I copy pasted the code from the tutorial and It did the same thing, but here is my code anywhere. I have also verified view.ShowExpanders is set to true
Application.Init();
Window window = new Window("Editor Window");
window.SetPosition(WindowPosition.Center);
window.HeightRequest = 800;
window.WidthRequest = 1200;
TreeView view = new TreeView();
view.WidthRequest = 500;
TreeViewColumn column = new TreeViewColumn();
column.Title = "Heirarchy";
CellRendererText cell = new CellRendererText();
column.PackStart(cell, true);
view.AppendColumn(column);
column.AddAttribute(cell, "text", 0);
TreeStore store = new TreeStore(typeof(string));
TreeIter i = store.AppendValues("Project");
i = store.AppendValues(i,"Room1");
i = store.AppendValues(i, "Item");
store.AppendValues(i, "Attribute");
store.AppendValues(i, "Attribute");
store.AppendValues(i, "Attribute");
view.ShowExpanders = true;
view.Model = store;
view.ShowExpanders = true;
window.Add(view);
window.DeleteEvent += ExitWindow;
window.ShowAll();
Application.Run();
Is there some sort of image asset that doesn't exist on my computer? How would I install that on mac? Thank you for any help you can provide.
As a comment suggested, using brew install adwaita-icon-theme fixed the problem

BindingInflate with different ViewModel

In my android view, I try to create a bunch of LinearLayouts using BindingInflate. It actually works fine, but I need to provide another ViewModel as DataContext. How do I achieve this?
In xaml I would just use
newLayout.DataContext = mySecondViewModel;
Following code is obviously not working, but something I would like to use:
var layout = this.BindingInflate(Resource.Layout.statistics_header, layoutContainer);
layout.BindingContext = mySecondViewModel
UPDATE:
Thanks for the comment - I did not know about the FrameControl. But unfortunatly I still could not figure out, how to use this.
What I want to achieve, is to fill up a viewpager with some fragments and a relative layout with corresponding headers. It would be easy to connect them to the same viewmodel.
Here is my current code:
var relativeLayout = FindViewById<RelativeLayout>(Resource.Id.statistics_header);
var layoutContainer = new MvxFrameControl(this, null)
{
LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent),
DataContext = statistic,
};
var layout = this.BindingInflate(Resource.Layout.statistics_header, layoutContainer);
relativeLayout.AddView(layoutContainer);
return new MvxPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(StatisticsFragment),
Title = "StatisticsFrag",
ViewModel = statistic,
ConnectedView = layoutContainer
};
It fails that it's not possible to bind. But the DataContext is set to the right ViewModel where every property is set.
Am I missing a point?
Regarding to Stuarts comment I answer this for him:
I need to use a MvxFrameControl and can set the DataContext:
var layoutContainer = new MvxFrameControl(Resource.Layout.statistics_header, this, null)
{
LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent),
DataContext = statistic
};
layoutContainers.Add(layoutContainer);
return new MvxPagerFragmentAdapter.FragmentInfo
{
FragmentType = typeof(StatisticsFragment),
Title = "StatisticsFrag",
ViewModel = statistic,
ConnectedView = layoutContainer
};

How to change window background color in mono (GTK)?

I have a window in gtk which includes a Build() function as follow:
protected virtual void Build()
{
global::Stetic.Gui.Initialize(this);
// Widget Client.Forms.Notification
this.Name = "Client.Forms.Notification";
this.Title = "Notification";
this.TypeHint = Gdk.WindowTypeHint.Normal;
//this.TypeHint = ((global::Gdk.WindowTypeHint)(4));
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
// Container child Client.Forms.Notification.Gtk.Container+ContainerChild
this.vbox1 = new global::Gtk.VBox();
this.vbox1.Name = "vbox1";
this.vbox1.Spacing = 6;
// Container child vbox1.Gtk.Box+BoxChild
this.label1 = new global::Gtk.Label();
this.label1.HeightRequest = 20;
this.label1.Name = "label1";
this.label1.LabelProp = "Notification";
this.vbox1.Add(this.label1);
global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.label1]));
w1.Position = 0;
w1.Expand = false;
w1.Fill = false;
// Container child vbox1.Gtk.Box+BoxChild
this.hbox1 = new global::Gtk.HBox();
this.hbox1.Name = "hbox1";
this.hbox1.Spacing = 6;
// Container child hbox1.Gtk.Box+BoxChild
this.image1 = new global::Gtk.Image();
this.image1.Name = "image1";
this.image1.Pixbuf = global::Gdk.Pixbuf.LoadFromResource("Client.Resources.icon.png");
this.hbox1.Add(this.image1);
global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.image1]));
w2.Position = 0;
w2.Expand = false;
w2.Fill = false;
// Container child hbox1.Gtk.Box+BoxChild
this.label2 = new global::Gtk.Label();
this.label2.Name = "label2";
this.label2.WidthRequest = 260;
this.label2.Wrap = true;
this.label2.LabelProp = "Description";
this.hbox1.Add(this.label2);
global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox1[this.label2]));
w3.Position = 1;
w3.Expand = false;
w3.Fill = false;
this.vbox1.Add(this.hbox1);
global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.vbox1[this.hbox1]));
w4.Position = 1;
w4.Expand = false;
w4.Fill = false;
this.label1.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
this.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
this.vbox1.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
root = new Gtk.EventBox();
root.Add(this.vbox1);
this.Decorated = false;
this.Add(root);
if ((this.Child != null))
{
this.Child.ShowAll();
}
this.DefaultWidth = 460;
this.DefaultHeight = 220;
}
(source code of this whole window: https://github.com/pidgeonproject/pidgeon/blob/master/Forms/Notification.cs)
As you can see it is calling
this.ModifyBase(Gtk.StateType.Normal, Core.fromColor(System.Drawing.Color.Orange));
which should change the background to orange, however it doesn't.
I tried to insert more similar functions on window elements, but it doesn't work either, does anyone know how to change the background color of the window?
What I want to do is create a small window with no decoration (so just a rectangle) of specific color and some text in it. This window is supposed to be transparent (that works now) and should have a picture and 2 labels with text and disappear on click - all this works now just I can't change the background from gray to some better color. I would be happy for answers that would let me do this using some other way (I can think of creating a small form just with drawing area and paint it with the color and then paint the text as well, but it sounds to me quite complicated for something so simple as I want to do).
NOTE: mono is using GTK 2, and the version of GTK# for .Net is using 2.12.20
Try to use Event Box. Seems to work
For GTK+2 you need to create a gtk resource like so:
char *my_custom_style = "style \"my-style-name\" { bg[NORMAL] = \"#339933\" }\nclass \"GtkWindow\" style \"my-style-name\"";
then load the resource when you start the program, after initialization:
gtk_rc_parse_string (my_custom_style);
Now any GtkWindow will use your custom style for it's background.
The C documentation for Gtk Resource Files
Edit:
If you only want to change one specific window, then you'd change the custom style string to something like
char *my_custom_style="style \"my-style-name\" { bg[NORMAL] = \"#339933\" }\nwidget \"my-custom-window\" style= \"my-style-name\"';
You then set the name of the window you want to change the background with
gtk_widget_set_name (GTK_WIDGET (my_window), "my-custom-window");
Edit 2:
Here's the documentation to the Gtk# Rc parsing function:
http://buttle.shangorilla.com/1.1/handlers/monodoc.ashx?link=M%3aGtk.Rc.Parse(System.String)
The documentation (for the C API) says that gtk_widget_modify_color() is deprecated, and that newly written code should use gtk_widget_override_background_color() instead, so try that.
Overriding themes in GTK+ is notoriously hard though, but the 3.0 API really sounds as if it's supporting what you want to do.
Can't test this myself at the moment, unfortunately.

How to open a dialog center-screen or center-owner?

I have a MVVM application and I have a main viewmodel. In this model I use the following code to open a dialog:
dlgViewModel myDlgViewModel = new dlgViewModel();
dlgView myDlgView = new dlgView();
myDlgView.DataContext = myDlgViewModel;
myDlgView.Owner = App.Current.MainWindow;
myDlgView.WindowStartupLocation = WindowStartupLocation.CenterOwner;
myDlgView.ShowDialog();
Also, in the XAML on my dlgView, I set the WIndowsStartupLocation to CenterOwner. However the window does not open in the center of the owner. I tried CenterScreeen but that does not work either.
How can I open a new view using the centerOwner or centerScreen option?
Well, the first time thing is set in the axml of my dialog WindowsStartUpLocation to center owner.
Then, in the main view model, I use this code:
dlgViewModel myDlgViewModel = new dlgViewModel();
dlgView myDlgView = new dlgView();
myDlgView.DataContext = miDlgViewModel;
myDlgView.Owner = App.Current.MainWindow;
myDlgView.ShowDialog();

Changing Contol Parent Removes Content

In my application, I have a DataGridView that moves from one Tab Control to another Tab Control.
I am doing this by changing its parent. This works with no problems on the first move from the origional Tab Control to the new one, but when changing the parent back to the origional, the DataGridView shows up (all the Columns are visible) but there is no data in the view.
I have tried to reload the data into the DataGridView, and refresh/Invalidate the control to make it redraw, but it still shows up empty. However, when the control goes back to the secondary parent, the data is back.
I am also using this exact code for another DataGridView and it works without any problems at all.
Any ideas would be greatly appreciated, and thanks in advance.
From Origional to Secondary
gvwRFIs.Parent = tabProcessingRFI; //Working
gvwConsentInfoMemos.Parent = tabProcessingMemos; //Working
From Secondary to Origional
gvwRFIs.Parent = tabConsentInfoRFI; //Empty Data
gvwConsentInfoMemos.Parent = tabConsentInfoMemos; //Working
RFI DataGridView Designer Code
//
// gvwRFIs
//
this.gvwRFIs.AllowUserToAddRows = false;
this.gvwRFIs.AllowUserToDeleteRows = false;
this.gvwRFIs.AllowUserToResizeRows = false;
this.gvwRFIs.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
this.gvwRFIs.BackgroundColor = System.Drawing.Color.White;
this.gvwRFIs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gvwRFIs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.gvwID,
this.gvwType,
this.gvwSeq,
this.gvwCreated,
this.gvwProcessor,
this.gvwLetter,
this.gvwResponded,
this.gvwS,
this.gvwDetails});
this.gvwRFIs.Dock = System.Windows.Forms.DockStyle.Fill;
this.gvwRFIs.Location = new System.Drawing.Point(3, 3);
this.gvwRFIs.MultiSelect = false;
this.gvwRFIs.Name = "gvwRFIs";
this.gvwRFIs.ReadOnly = true;
this.gvwRFIs.RowHeadersVisible = false;
this.gvwRFIs.RowHeadersWidth = 4;
this.gvwRFIs.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.gvwRFIs.Size = new System.Drawing.Size(1078, 422);
this.gvwRFIs.TabIndex = 4;
this.gvwRFIs.DoubleClick += new System.EventHandler(this.gvwRFIs_DoubleClick);
Consent Tab Control Designer Code
//
// tabConsentInfoRFI
//
this.tabConsentInfoRFI.Controls.Add(this.gvwRFIs);
this.tabConsentInfoRFI.Controls.Add(this.lvwConsentInfoRFI);
this.tabConsentInfoRFI.Location = new System.Drawing.Point(4, 32);
this.tabConsentInfoRFI.Name = "tabConsentInfoRFI";
this.tabConsentInfoRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabConsentInfoRFI.Size = new System.Drawing.Size(1084, 428);
this.tabConsentInfoRFI.TabIndex = 4;
this.tabConsentInfoRFI.Text = "RFI\'s";
this.tabConsentInfoRFI.UseVisualStyleBackColor = true;
Processing Tab Control Designer Code
//
// tabProcessingRFI
//
this.tabProcessingRFI.Location = new System.Drawing.Point(4, 36);
this.tabProcessingRFI.Name = "tabProcessingRFI";
this.tabProcessingRFI.Padding = new System.Windows.Forms.Padding(3);
this.tabProcessingRFI.Size = new System.Drawing.Size(868, 465);
this.tabProcessingRFI.TabIndex = 1;
this.tabProcessingRFI.Text = "RFI";
this.tabProcessingRFI.UseVisualStyleBackColor = true;
I found the issue,
The ListView that is in the consent designer code, is an old control that looks identical, but is no longer used. So when the control is parented back to the Origional tab, it is in the background of this control.
Once the control was removed (thought it already was) the code worked perfectly.
Thank you to LarsTech for getting me in the right direction. And akhisp for there answer.
You should remove the object from the Tab.Controls list of the tab that it's no longer in. So do something like:
tabProcessingRFI.Controls.Remove(gvwRFIs);
gvwRFIs.Parent = tabConsentInfoRFI

Categories