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

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();

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

How to create new tabs in xamarin forms web view

I want to make my web-view support multiple tabs .
how to do it for example like this code :
browser.newtab(URL:"google.com",tabindex:1);
How to do it in android and ios ?
That is not possible. WebView (and its native counterparts) don't support the tab browsing. So there is not a single line of code that will resolve your problem You must create the tab UI yourself and manage everything related to it.
Easiest solution is to go for tabbed page. Example:
private ContentPage NewBrowserTab(string url)
{
var cp = new ContentPage();
cp.Title = url;
var wv = new WebView();
wv.Source = url;
cp.Content = wv;
return cp;
}
And tabbed page:
TabbedPage tp = new TabbedPage();
tp.Children.Add(NewBrowserTab("https://google.com"));
tp.Children.Add(NewBrowserTab("https://xamarin.com"));
App.Current.MainPage = new NavigationPage(tp);

Keep window on top WPF

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();
}

onCreateView not called on fragment that was inflated by layoutinflator

I have a layout that I want to show as a popup window (used as a custom options menu) while in a fragment of a viewpager. Therefore, when the "Options" button is clicked, I do the following:
public void onOptionsButtonClicked(int buttonHeight)
{
LayoutInflater optionsLayoutInflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
int popupWidth = ViewGroup.LayoutParams.MatchParent;
int popupHeight = ViewGroup.LayoutParams.WrapContent;
View layout = optionsLayoutInflater.Inflate(Resource.Layout.TrackOptions, null);
int popupYOffset = (85 + buttonHeight) * -1;
var popup = new PopupWindow(context);
popup.Focusable = true;
popup.Width = popupWidth;
popup.Height = popupHeight;
popup.ContentView = layout;
popup.SetBackgroundDrawable(new BitmapDrawable());
popup.OutsideTouchable = true;
popup.ShowAsDropDown(view, 0, popupYOffset);
}
And this works as I want, visually that is. Meaning, I click the button and I do see the layout popup as a popup window with all of my options. HOWEVER, none of the buttons work. I put a breakpoint in the class that should be associated the the layout and noticed that onCreateView never gets called, therefore, none of the buttons and associated click event handlers are ever wired up. So, I know why it is not working. However, I don't know how to fix it. I think it is because, while I inflate the view, I am never actually creating the fragment. I have done fragementmanager transactions to replace a fragment in other parts of my project and I know that would probably do it, however, this is a different case as I am trying to do a popup window.
Thanks!
Mike
Fragment is attach in activity so you can try it in onActivityCreated(Bundle) method

How can I add this WPF control into my WinForm?

I know that I must use an ElementHost to display a WPF control in a WinForm, but as the WPF control is third party software and it only comes with an XML file and a DLL file.
The control is AvalonEdit, I added both the ICSharpCode.AvalonEdit.xml and ICSharpCode.AvalonEdit.dll files to my project, and I went to Project -> Add Reference and added the DLL as a reference. Now I can access the ICSharpCode namespace in my code, all of the classes and methods are exposed, but from this point I am unsure how to actually use the control in my WinForm.
I was expecting a WPF control to appear in the Solution Explorer, but it does not. I tried adding an ElementHost control to my WinForm anyways, but when I try to Select the Hosted Content, no controls appear, so it doesn't know about my WPF control. How can I use the AvalonEdit WPF control in my WinForm?
If you want to be able to set the hosted content at design time the control needs to be part of your solution. One way to achieve that is to create a custom WPF user control which contains the AvalonEdit component you want to use. I.e
Create a WPF User Control library project and create a user control
containing the AvalonEdit component.
Add the User control project to your Winforms solution.
Now you should be able to select your new user control as the hosted content.
Or you could add the AvalonEdit control directly in code like this:
public Form1()
{
InitializeComponent();
ElementHost host= new ElementHost();
host.Size = new Size(200, 100);
host.Location = new Point(100,100);
AvalonEditControl edit = new AvalonEditControl();
host.Child = edit;
this.Controls.Add(host);
}
Not sure what the control is called so replace the AvalonEditControl as appropriate.
You'll want an example on how to do Code Colouring/Syntax Highlighting as well:
public Form1()
{
InitializeComponent();
ICSharpCode.AvalonEdit.TextEditor textEditor = new ICSharpCode.AvalonEdit.TextEditor();
textEditor.ShowLineNumbers = true;
textEditor.FontFamily = new System.Windows.Media.FontFamily("Consolas");
textEditor.FontSize = 12.75f;
string dir = #"C:\Temp\";
#if DEBUG
dir = #"C:\Dev\Sandbox\SharpDevelop-master\src\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\Highlighting\Resources\";
#endif
if (File.Exists(dir + "CSharp-Mode.xshd"))
{
Stream xshd_stream = File.OpenRead(dir + "CSharp-Mode.xshd");
XmlTextReader xshd_reader = new XmlTextReader(xshd_stream);
// Apply the new syntax highlighting definition.
textEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(xshd_reader, ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance);
xshd_reader.Close();
xshd_stream.Close();
}
//Host the WPF AvalonEdiot control in a Winform ElementHost control
ElementHost host = new ElementHost();
host.Dock = DockStyle.Fill;
host.Child = textEditor;
this.Controls.Add(host);
}
ElementHost host = new ElementHost();
host.Size = new Size(200, 100);
host.Location = new Point(100, 100);
ICSharpCode.AvalonEdit.TextEditor edit = new
ICSharpCode.AvalonEdit.TextEditor();
host.Child = edit;
this.Controls.Add(host);

Categories