I am a bit confused regarding C# WPF. How can I set a WPF window's properties from C# code? For example, trying ShowInTaskbar = false; doesn't hide the window's taskbar button, I actually have to do it in XAML for it to work. And that wouldn't be a problem, but I wonder, how do I control the GUI from C# code when using WPF.
This may sound like a retarded question, but I am trying to transition from WinForms to WPF.
you simply need the instance/reference of Window then you can do whatever you want with it in code.
try windowInstance.ShowInTaskBar = false in code it should work
Related
I am developing a Windows Form Application. I want to Align the Text to Right of Title Bar of Form. I set RightToLeft property to Yes, it worked in design time but didn't work in run time.
How can I do it? I don't want to set RightToleftLayout to True.
I think you don't have a function or something of visual studio who can lead you to do this.
The title bar of winforms is a native application of Windows, so it's not a good idea to move things on it.
But if you really want to do that, or you really need to, you can do something like this:
this.Text = " " + this.Text;
And modify any way you want.
i am working on winform application , one screen of my application i am using a wpf user control . i am setting visiblity of that WPF user control through binding.
there is no threading in my application, i want that as soon as set the visiblility of user control it should effect in UI,but is not happening like that.
i am able to see my WPF user control after the screen is loaded fully.
Hi,
i am working on winform application , one screen of my application i am using a wpf user control . i am setting visiblity of that WPF user control through binding.
there is no threading in my application, i want that as soon as set the visiblility of user control it should effect in UI,but is not happening like that.
i am able to see my WPF user control after the screen is loaded fully.
my code somewhat look like this
void Dosomething()
{
IsUserControlEnabled=true;//here the UI should reflect but not happening
//some time taking code assume 4-8 sec
IsUserControlEnabled=false;
}
What I have tried:
void Dosomething()
{
IsUserControlEnabled=true;//here the UI should reflect but not happening
//some time taking code assume 4-8 sec
// if aim not setting IsUserControlEnabled=false then i am able to see in my UI but i want that in this method only it should appear an disappear
}
i am assuming my problem is releated to below link
my problem is somewhat releated to this link
Make sure the class which you are binding to is implementing INotifyPropertyChanged and that you're raising a PropertyChanged event in the get accessor of your IsUserControlEnabled property. Your UserControl listens for PropertyChanged events to know when to update the control's visual properties, and if it doesn't get them it won't know to update itself.
How can I remove the minimize and maximize buttons on a gtk# window, I came across
this, but wasn't very sure how to use it in gtk#.
This GTK# thread discusses the given indirect method in Mono terms.
this.TypeHint = Gdk.WindowTypeHint.Dialog;
It uses value from WindowTypeHint enumeration to set Window.TypeHint property to WindowTypeHint.Dialog value.
P.S.: I was unable to find any good references for GDK# documentation.
Here is a hacky way to remove the minimize button (this is tested on Raspbian Jessie)
Set the window type to WindowTypeHint.Menu
But, when the window starts it won't be focused, which isn't good. So, in the constructor of the dialog, after the this.Build (); line, add this: this.Present (); and it will focus the window.
I am trying to create a popup but when it is open it is still possible to use the tab key to switch the focus to an element in the background (e.g. to a button and use space to press is). The only way I found until now is to check on every lostFocus event (which also fires for every element contained in the Border element) and check if the focus is now in a element inside the Border. If not I manually set the focus.
Is there a nicer way to keep the focus within the Border (or a Grid,...)
I'm working on a Windows 8 App.
Do you mean that using a Modal Dialog with Form.ShowDialog(Owner) still allows you to focus the parent components with Tab?
Can you give a sample of your code call?
Form2 form = new Form2(); //Make an instantiation of your Form
form.ShowDialog(); //ShowDialog()!!! NOT form.Show()!!! Or anything else :/
A few ideas:
Set Enabled to False on the background visual tree, though that might change the way things look if you still want to show them partly
Set IsHitTestVisible to False to disable pointer input
Use RenderTargetBitmap.Render() if targeting Windows 8.1 to render the content of the background to an image and simply replace all that visual tree with an image of it
I was wondering if anyone can help me with this rather baffling situation. I have a WPF form myForm which I am displaying modally in a WinForm application (without using an ElementHost). Everything works fine if I use the default WindowStyle and it is shown in the taskbar. However now I don't want the form to show in the taskbar or contain the minimize button, therefore I have done the following:
MyForm myForm = new MyForm();
myForm.ShowInTaskbar = false;
myForm.WindowStyle = System.Windows.WindowStyle.ToolWindow;
myForm.WindowStartupLocation =System.Windows.WindowStartupLocation.CenterOwner;
myForm.ShowDialog();
Now, the wpf form displays as expected modally and without the minimize button. If I now select the "parent" winform application in the taskbar, the wpf form disappears and there doesn't seem to be any way of returning to it! I have read this which is similar but not the same (pure WPF application), so I can understand why the main app does not appear in the ALT+TAB menu, but can anyone tell me how I can return to the wpf form?
Thanks in advance.
The use of WindowsInteropHelper allows you to wrap a hosted WPF-form using a Winforms-form and set its parent as a Winforms control, which prevents the WPF form from disappearing (as also pointed out by dowhilefor and Hans Passant)
E.g.:
// Use the interop helper for the specified wpf window hosted by the win32 owner
WindowInteropHelper wih = new WindowInteropHelper(wpfForm);
wih.Owner = this.someWin32FormsControl.Handle;
This is not related to Winforms or WPF, this is the way Windows functions. The only solution that I think you have is to wire up your modality; that is intercept the Activated event on your Winforms form and if your WPF tool window is visible, bring that window forward and give it focus.