I have a question regarding the ThemeManager class of MahApps.Metro.
I created a simple wpf application that has a MetroWindow as root element, and its working perfectly.
Now I am trying to change the theme/style of the application with a click on a button.
This is my code:
private void Button_OnClick (object sender,RoutedEventArgs e)
{
ThemeManager.ChangeAppStyle (Application.Current,ThemeManager.Accents.First(acc=>acc.Name=="Red"),ThemeManager.AppThemes.Last());
}
I know its a bad practice to do it like that but its just a concept for what i am trying to do.
I put a breakpoint on that line and the debugger does reach it, but it does nothing :(
Con someone please help me?
Thanks a lot!
Related
I am using gif animation in WPF application, an external dll WpfAnimatedGif.dll is used for showing the animation. The animation is working properly, but I am unable to pause/stop it on a certain event let say button click, how can I do it, kindly guide me, my xaml code is given below
<Image x:Name="scaner" Stretch="UniformToFill" gif:ImageBehavior.AnimatedSource="{StaticResource gifImage}" >
According to your documentation (which you should have read yourself) this will work:
private void Button_Click(object sender, RoutedEventArgs e)
{
var controller = ImageBehavior.GetAnimationController(this.scaner);
controller.Pause();
}
Please note that working directly with button functions is not the prefered way in WPF, if you want to use the full power I suggest using MVVM and the command pattern instead.
You can try this, use reference
xamlAnimationWpf Nuget <br>
var controller = AnimationBehavior.GetAnimator(myGif); <br>
controller.Pause();<br>
For those who try another way
I have created a wpf application for context sensitive help using .chm files. I have created a a context sensitive help by pressing F1 after clicking a textbox or a button, thorugh xaml, AND NOT BY EVENT HANDLING. , but I need it for window also. I can have the window help as default in xaml when the window is loaded itself, which works now. But if i use text box help, then I cant switch back to window help since I have not included any events for that.
For this scenario, is using events the only possibility to include window help? what is the best practice? Is there a way to use window focus on xaml itself, or using event ends up as the best practice?
thanks a lot !!
Why not just implement a F1 Help System? it's pretty straightforward...
Take a look at this example HERE. This provides a HelpProvider class that gives you context sensitive help on any element that sets a HelpString. This should provide roughly what you need.
In your case, just make the chm file name your help name for each element you want a file sensitive to. And you could have something like so:
static private void Executed(object sender, ExecutedRoutedEventArgs e)
{
YourHelpSystem.ShowHelp(HelpProvider.GetHelpString(sender as FrameworkElement) + ".chm");
}
I'm new into WPF and have a problem I can't seem to find a solution for.
I'm writing a G19 (Keyboard) applet. This Keyboard has a 320x240 display attached, which you can access with C#.
I'm using WPF for this, because I don't need to do any GDI drawing anymore and use the normal controls instead.
So. It works as I wish. Everything draws properly except one UserControl. I have downloaded this control -> http://marqueedriproll.codeplex.com/
In the designer, the control works, the Loaded event get's fired and the animation is good.
When I run my application, I just see the label and the text. The animation does not work, and the Loaded event does not fire anymore.
Any help is appreciated.
The main function is my wrapper. The wrapper is already a Usercontrol and displays plugins which are switchable. This wrapper has the Frame Control(Wrapper1). I replace the content of this frame every time I switch the plugin.
public void SetPlugin(IPlugin plugin)
{
if (this.MainPlugin != null)
{
this.MainPlugin.OnHide();
((UserControl)this.MainPlugin).Visibility = System.Windows.Visibility.Hidden;
}
this.MainPlugin = plugin;
((UserControl)this.MainPlugin).Visibility = System.Windows.Visibility.Visible;
this.MainPlugin.OnShow();
this.Wrapper1.Content = this.MainPlugin;
}
I think it's the right approach to handle a plugin system that way. The plugin get's drawed on my keyboard.
What I don't understand is why the usercontrol only works in the designer view and not in the running application.
The basic code of the scrolling label is so:
public MarqueeText()
{
this.Loaded += new RoutedEventHandler(MarqueeText_Loaded);
InitializeComponent();
canMain.Height = this.Height;
canMain.Width = this.Width;
}
void MarqueeText_Loaded(object sender, RoutedEventArgs e)
{
StartMarqueeing(_marqueeType);
}
I don't see a reason why it doesn't work. Actually Ive always found a way to fix a problem but this time I see nothing.
Thanks in advance. Your help is really required today.
Have a great saturday! :)
I am guessing you are rendering to a bitmap target, rather than onscreen. If you are using RenderTargetBitmap, you have a couple of responsibilities. You need to set both a presentation source, and make sure you run events on the dispatcher.
Normally, App.xaml or Application.Run does this for you, but if you are not using a Window, you are on your own.
See this related question for details.
I am new to WPF and C# and i need some help - sorry about the newbie question!
Anyway I have a control panel 'window' as the file thats loaded when i run my project, and i then have a button on this control panel, that when clicked triggers an event. Inside this 'event function' I am trying to load a new window that has its own XAML code behind, how do i go about doing this? I have googled but to no avail.
Please explain in laymens terms, I am still getting the hang of this all.
Thanks!
private void btnCustomers_clicked(object sender, RoutedEventArgs e)
{
//load in Customers.xaml file here - in a new window
}
You need to declare an instance of the class that is your other window then call Show() on it. So if your other window is call MySecondWindow you write the following in your event handler.
MySecondWindow otherWindow = new MySecondWindow();
otherWindow.Show();
A basic explination of how windows work can be found on the MSDN Site.
I have a C# Winforms app that uses the HelpProvider class.
Whenever i press F1 to bring up help, the help window will always be on top of my application, I cannot bring my application UI to the foreground. I can still interact with my UI, but the help window will remain on top.
Is this by design of HelpProvider? Or am I missing something?
There is a solution to this issue, a bit dirty, but it works.
The thing is, the help window opened by HelpProvider is always on top of its parent window control, which is determined by Control instance in first parameter of Help.ShowHelp. Even if you specify null there, the main application form is still used as parent window.
To avoid this, one can create a dummy form, which will be used as a help parent form. This form will be never shown, but still, help window will be “on top” of it, effectively being NOT on top of all other application windows.
public static class AppHelp
{
private static Form mFrmDummyHost = new Form();
public static void ShowChm()
{
Help.ShowHelp(mFrmDummyHost, "my_help.chm");
}
}
Of course, all other Help.ShowHelp overloads can be called this way as well.
Hope this helps people like me, searching for answers to never-getting-old questions ;)
It is indeed by design, and its something that i did not realise. I have just recompiled my final year project and confirmed it. I have read up about it and basically the help file is set to TopMost=True every time the form is clicked. This means even if you code your form to be TopMost, as soon as you click the help file it will go back on top again.
I do believe if you use start process, it should get around the issue at the loss of some customisability the help provider gives.
private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode ==Keys.F1)
{
System.Diagnostics.Process.Start(#"C:\WINDOWS\Help\mspaint.chm");
}
}
Hope it helps