I'm working with a .NET 3.5 application that is using System.Windows.Forms.OpenFileDialog. However, no matter what I do, the open dialog only shows the XP-Style version. I've made the code as simple as possible:
OpenFileDialog openFileDialog = new OpenFileDialog()
//openFileDialog.AutoUpgradeEnabled = true; //Adding this line does nothing
if(DialogResult.OK == openFileDialog.ShowDialog())
{ ... }
No matter what I do, the dialog always shows the old XP-Style version instead of the new Vista+ version. I also noticed that when I debug and look at some parameters, there's a protected member variable somewhere in the chain: SettingsSupportVistaDialog, which in this instance is set to false. I'm not sure if that is the issue, or where/why this could be getting set.
Does anyone have any suggestions?
Here's a screenshot of the existing (XP-style) dialog
Here's what I want it to look like:
I found the problem. I had to dig into the .NET 3.5 source code, but it turns out that if Application.VisualStyleState isn't set to ClientAreaEnabled or ClientAndNonClientAreasEnabled the old XP-style dialog will be used.
Related
I want to open a PDF with the default windows behaviour the user has saved (e.g. internet explorer, adobe, whatever).
I found this solution
Opening a .pdf file in windows form through a button click
and implemented it here:
ProcessStartInfo startInfo = new ProcessStartInfo("MyPdfPath");
Process.Start(startInfo);
Sadly I got an Error:
System.ComponentModel.Win32Exception: "The specified executable is not a valid application for this OS platform."
I tried to google this error, but nothing of the first ten solution ideas worked.
The system is treating it like an executable, one way to get the document behavior is to set UseShellExecute to true:
ProcessStartInfo startInfo = new ProcessStartInfo("MyPdfPath");
startInfo.UseShellExecute = true;
Process.Start(startInfo);
I'm working on a C# project with WPF in Visual Studio. My application was building and running perfectly yesterday. As far as I know, I haven't made any changes to the build process.
Today, when I try to run a Debug build, it builds and deploys correctly, and a process starts, but the application startup window never displays (not even in the Windows Taskbar). I tried to attach the Visual Studio Debugger to the process as recommended in this (external) link, but the process is grayed out in the Visual Studio > Debug > Attach to Process... popup. It does not display even if I browse to the Debug folder and double-click the *.exe file.
The unusual thing about this is that if I run in Release rather than Debug, everything works fine. I've checked the Project > Properties > Debug configurations; Debug and Release are identical (I just used the defaults when I created the project). Other projects also work fine in both Debug and Release build. I tried comparing the *.csproj and *.sln files, but I couldn't find any significant differences.
I've tried searching for this, but it's really difficult to find anything useful. This question is unrelated, since the window does not even appear in the taskbar in my case. If I try to include the word "debug," I get a flood of questions about redirecting output to the console, which is not my problem.
I'm not sure what code/configurations are relevant to this question, so please let me know if you need more info about the setup.
Edit 1:
I tried putting a break in the InitializeComponent() method in the auto-generated part of my App class:
public partial class App : System.Windows.Application {
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
#line 5 "..\..\App.xaml"
this.StartupUri = new System.Uri("Views\\MainWindow.xaml", System.UriKind.Relative);
#line default
#line hidden
System.Uri resourceLocater = new System.Uri("/MyProject;component/app.xaml", System.UriKind.Relative);
#line 1 "..\..\App.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main() {
MyProject.App app = new MyProject.App();
app.InitializeComponent();
app.Run();
}
}
This will break for either Debug or Release if the code is between if(_contentLoaded) { and _contentLoaded = true; but everywhere else in the method, I get "The breakpoint will not currently be hit. No executable code of the debugger's target code type is associated with this line." I get the same message if I try to put a breakpoint anywhere in the Main() method.
Even though Debug breaks at the certain interval mentioned above, it still does not display if I continue.
Edit 2:
Things are starting to get weird. Since the project is backed up in Git, I rolled all the way back to the first commit and to several others along the way. I still couldn't get anything to display for Debug, but Release still worked fine. I even tried deleting the local repo and recloning it, but no success. The stranger part about this is that everything runs fine from the backup folder. Why does the folder name make a difference?
I never found out what caused the issue to occur in the first place, but I was eventually able to come up with two workable solutions.
As described in the edit: Copying the solution directory to another directory and running it from there works for some reason.
For some reason, running Debug|Any CPU didn't work, but running either Debug|x86 or Debug|x64 did.
It's unlikely that someone else will run into my exact situation, but I'm leaving my solutions here for posterity. Maybe someone else can benefit from this.
I have an Excel add-in with a button on it that calls a WPF application on a new thread. When I close Excel not having opened my WPF application or after opening it and then closing it again, Excel closes immediately, however, whenever I open the application and then close Excel, Excel takes 5-10 seconds to close. I've only come across these solutions, neither of which has helped:
VSTO Runtime Update to Address Slow Shutdown...
This one sort of asks the question, but the asker's issue ends up being different.
I'm running VS 2010 and Excel 2010, so there shouldn't be an interoperability problem.
Does anyone have a suggestion?
Thread Code:
Private qbdThread As Thread = Nothing
Private frmQBD As QBDApplication.MainWindow
qbdThread = New Thread(New ParameterizedThreadStart(AddressOf RunQBD))
qbdThread.SetApartmentState(Threading.ApartmentState.STA)
qbdThread.Start(TabletType)
AddHandler QBDApplication.MainWindow.QBDClose, AddressOf QBDThreadClose
Private Sub RunQBD(Optional tabletQBDSelected As String = Nothing)
...
frmQBD = New QBDApplication.MainWindow(contacts, saveLocation, tabletQBDLocal)
frmQBD.Show()
frmQBD.Activate()
System.Windows.Threading.Dispatcher.Run()
End Sub
This code runs when the app is closed by the user on the new thread:
Me.Close()
System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown()
An event is then raised on the main thread (ThisAddin.vb) with this code:
Private Sub QBDThreadClose()
qbdThread = Nothing
frmQBD = Nothing
End Sub
One other thing to note is that when frmQBD is not created as a class variable, and instead dimensioned in the "RunQBD" sub, this issue does not occur. This would solve my problem, but then I wouldn't be able to access something like frmQBD.Activate() on the main thread, which I need to be able to do.
EDIT: Code has been updated
We found a solution for this problem.
You have to set an AppSwith in the framework
Public Sub EnablePointerSupport()
AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.EnablePointerSupport",True)
End Sub
You can find more information about it here and here.
This Microsoft bug is described at https://connect.microsoft.com/VisualStudio/feedback/details/783019/word-slow-shutdown-on-windows-8-when-using-wpf-in-application-addin. It was initially reported in 2013 and supposedly fixed in 2014, but appears to be back now.
We can reproduce this exact problem with Excel and Word 2016 running on Windows 10, but mysteriously not in PowerPoint. Latest version of VSTO Runtime is installed. We could not reproduce the problem in Office 2013 running on Windows 8.1.
The workaround is as described at the link above--go to Device Manager > Human Interface Devices and disable "HID-compliant touch screen" (in our testing) or perhaps another one of the "HID-compliant" items.
Using the IHtmlDocument2.designMode property set to On to switch a WebBrowser control hosted on a Windows Forms form to editing mode suddenly stopped working after installing Microsoft Internet Explorer 9 RC.
Question:
Any chance to fix this?
I already tried to tweak with doctype or with the EmulateIE7 meta tag but without success.
(An example would be this project)
Update 2011-02-21:
As Eric Lawrence suggested, I adjusted the "Zeta" example to set the document text before setting the edit mode.
Unfortunately I did not manage to switch to design mode, either.
Update 2011-02-24:
Parts of the discussion also take place in Eric's blog.
Update 2011-02-26:
What I currently eperience is that the behaviour seems to be different for HTTP URLs and for content that was added via WebBrowser.DocumentText.
First tests seems to prove this assumption.
I'm now going to build a solution around this assumption and post updates and a proof-of-concept here.
Update 2011-02-26 (2):
I've now built a proof-of-concept with a built-in web server which I believe is also working well with IE 9. If anyone would like to download and test whether it is working and give me a short feedback, I can clean up and release the source code for this.
Update 2011-02-26 (3):
No feedback yet, I still updated the HTML Edit Control article and demo over at the Code Project.
Update 2011-03-16:
Since Internet Explorer 9 was released yesterday, we updated our major products to use the idea with the integrated web server as described in the HTML Edit Control article.
After nearly a month of testing, I think it works quite well.
If you do experience any issues in the future with this approach, please post your comments here and I can investigate and fix.
I had a similar problem and got around it by adding the following line to the DocumentCompleted event:
((HTMLBody)_doc.body).contentEditable = "true";
We just need an empty editable control. I did however step through debugger and add value to the control's InnerHtml and it displayed it fine, and I could edit it.
Small update, we were able to get the control editable using this line also:
browserControl.browser.Document.Body.SetAttribute("contentEditable", "true");
This allows us to avoid referencing mshtml, (don't have to include Microsoft.mshtml.dll)
This lets us avoid increasing our installation size by 8 megs.
What's your exact code?
If I set the following code:
private void cbDesign_CheckedChanged(object sender, EventArgs e){
var instance =
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(
wbView.ActiveXInstance,
null,
#"Document",
new object[0],
null,
null, null );
var objArray1 = new object[] { cbDesign.Checked ? #"On" : #"Off" };
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSetComplex(
instance,
null,
#"designMode",
objArray1,
null,
null,
false,
true );
The IE9 Web Browser instance enters designMode without any problems. If you change the "Zeta" example to not set the document text after entering design mode, it also works fine.
Just want to add that I am also unable to enter designmode (using a WebBrowser control in my case). This was not an issue in the beta. Definitely new with the RC.
Another Code Project user suggested to use the following code:
First, add event DocumentCompleted:
private void SetupEvents()
{
webBrowser1.Navigated += webBrowser1_Navigated;
webBrowser1.GotFocus += webBrowser1_GotFocus;
webBrowser1.DocumentCompleted += this.theBrowser_DocumentCompleted;
}
Then write the function:
private void theBrowser_DocumentCompleted(
object sender,
WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Write(webBrowser1.DocumentText);
doc.designMode = "On";
}
Although I did not test this, I want to document it here for completeness.
It's fixed if the property is set after the document is loaded
private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
IHTMLDocument2 Doc = Document.DomDocument as IHTMLDocument2;
Doc.designMode = #"On";
}
Yesterday, Internet Explorer 9 RTM finally was released.
I did some more tiny adjustments to my control, but basically the idea with the intergrated, small web server seems to work rather well.
So the solution is in this Code Project article:
Zeta HTML Edit Control
A small wrapper class around the Windows Forms 2.0 WebBrowser control
This was the only solution that worked for me.
I hope it is OK to answer my own question and mark my answer as "answered", too?!?
I was also able to get this to work using the following inside the DocumentCompleted event:
IHTMLDocument2 Doc = browserControl.browser.Document.DomDocument as IHTMLDocument2;
if (Doc != null) Doc.designMode = #"On";
Thanks everyone!
I use HTML Editor Control, I solved this problem adding the DocumentComplete event
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
(((sender as WebBrowser).Document.DomDocument as IHTMLDocument2).body as HTMLBody).contentEditable = "true";
}
I have a project which requires an image in the window. This is a static image and i added through 'Add>Existing Item'. It exists in the root of the project.
I reference the image in a test page like so -
<Page x:Class="Critter.Pages.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test">
<Image Source="bug.png"/>
</Page>
Problem is I get a message saying it can't be found or it's build action isn't resource but it DOES exist and it's build action IS resource. If i create a new application and just throw it on a window then it works fine.
Any help would be great.
Try doing a full rebuild, or delete the build files and then build the file.
Visual Studio doesn't always pick up changes to resources, and it can be a pain to get it recompile.
Also try using a full URI as that helped me when I had the same problem. Something like
pack://application:,,,/MyAssembly;component/bug.png
→ Right click the image file
→ Click property
→ Select Build Action to Resource
→ Clean and Build solution
→ Run the Solution
You will get the all.
I had the same issue. Cleaning and rebuilding the solution didn't fix it so I restarted visual studio and it did. Here's hoping Visual 2010 fixes this issue and the many others that plauge wpf in Visual 2008.
Try starting the path to your image with a "/":
<Image Source="/bug.png"/>
There is a solution to your question
<Image Source="/WpfApplication4;component/images/sky.jpg" />
"component" is not a folder!
It doesn't, or at least the current beta doesn't. I found this page while looking into exactly the same problem. Rebuild/clean did nothing. After closing down and reloading the solution the file magically became compatible again.
I faced the exact same issue but restarting VS2008 or cleaning and rebuilding the project did not work for me. In the end, the below steps did the trick.
In Windows Explorer copy the Image into your project resource folder. Example: MyProject\Resources\
From within Visual Studio right click on the Resources and select "Add > Existing item" and select the image which you have just copied in
From within the form XAML set the image source as: "Source="Resources/MyImage.ico" (my image was saved as icon (.ico) file, but this approach should work for any image type
Hope this helps someone
Example of async load, another option. Example clip.mp4 is in the web project root.
void Landing_Loaded(object sender, RoutedEventArgs e)
{
//Load video async
Uri pageUri = HtmlPage.Document.DocumentUri;
Uri videoUri = new UriBuilder(pageUri.Scheme, pageUri.Host, pageUri.Port, "clip.mp4").Uri;
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(videoUri);
}
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
byte[] VideoBuffer = new byte[e.Result.Length];
e.Result.Read(VideoBuffer, 0, (int)e.Result.Length);
MemoryStream videoStream = new MemoryStream(VideoBuffer);
ContentVideo.SetSource(videoStream);
ContentVideo.Stop();
ContentVideo.Play();
}
I had a similar problem. After I deleted a someStyle.xaml file that I wasn't really using from the solution explorer.
Then I restored the file, but no change happened. Cleaning and rebuilding the project did not help.
Simply deleting the corresponding row:
<ResourceDictionary Source="someStyle.xaml"/>
did the trick.
I had the same error message but my issues was a simple NOOB mistake.
When I added my .ico files to "My Project / Resources", VS made a sub folder named Resources and I was trying to use;
<Window Icon="icons1.ico">
when I should have been using;
<Window Icon="Resources/icons1.ico">
... don't judge, I started using WPF 1 week ago :)