WPF Custom Chrome Window? - c#

i have been trying to make something along the lines of this...
I have looked and looked and only found this article.
I am having trouble integrating this into my application. I just started WPF today, so i am learning. I have downloded the window.Shell dLL. What else do i need? Thanks!

If you are looking for a step-by-step guide on how to add this to your application I can give it a try; I just happened to need a bit of a brush-up for a small app, I liked this and gave it a try - it took me about 45 minutes to apply. Cool stuff actually!
First: Download the source application and extract it to your computer.
In it you will find three subfolders. One with the sample application, one named Microsoft.Windows.Shell, one named CustomChromeLibrary. Copy the latter two to the root folder of your project map, add them to your project map (add existing project) and, from your startup project, reference them.
Now open the Window you want to apply CustomChromeLibrary to. You need to change the root from
<Window>
to
<ccl:CustomChromeWindow>
, this is done by using this code as the document root:
<ccl:CustomChromeWindow
Title="YourWindowTitle" Height="268" Width="733" ResizeMode="CanResize"
x:Class="YourNamespace.YourWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
xmlns:ccl="clr-namespace:CustomChromeLibrary;assembly=CustomChromeLibrary"
xmlns:local="clr-namespace:YourNamespace"
>
Pay attention to the last three lines in the sample. These need to be updated to reference the correct libraries; the last one actually referencing to YOUR namespace.
Next you need to update the source code of your window as this is still a simple Window and you will receive an error from it.
Change this
public partial class YourWindow : Window
to this
public partial class YourWindow : CustomChromeLibrary.CustomChromeWindow
You are already half way there!
Next you just need to create the objects for your window (title bar etc.). This is wonderfully done in the sample project No. 5; I did really just copy it.
Take everything from
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome
...
to here
<!--min/max/close buttons-->
<ccl:CaptionButtons/>
Now you can fill your Window like this
<Grid>
The content of your Window goes here
</Grid>
And close the xaml like this
</Grid>
</ccl:CustomChromeWindow>
Now, if you try to run this you will receive another error. There are still three files missing:
The first one you need is a Microsoft file: CaptionButtonRectToMarginConverter.cs; you will also find it in the sample. Copy it to your project and add it (add existing file).
You need to make one change to it:
namespace YourNamespace
{ ...
instead of the sample's namespace.
Finally you need the two xaml files that create the buttons: GlassButton.xaml and GlassIcon.xaml; they can be found in the "Resources" subfolder (and are referenced as resource dictionaries in the xaml). Copy the whole subfolder to your project and add the two files to your project (add existing file).
Now you should finally be able to run your project.
Let's not forget this: Lots of kudos to gbahns, the author of the original article over at codeplex.com!

There are quite a few implementations you can find for a custom chrome.
Another helper library I've seen to one you linked is
MahApps.Metro
Read section 3. It can be setup with Nuget making it more easier to integrate for someone new.
Also section 3.3 3.4 3.5 talk about customising and expanding the MetroWindow control which gives you a custom chrome and also allows adding controls to the chrome title bar

Over in this stack overflow question:
How can I add a button to the WPF caption bar while using custom window chrome?
I was asking about how to insert buttons into the title bar of my Custom Window Chrome window. The xaml example might be enough to help you get going.
Other than that, I'm not sure what you are looking for.
Edit: The button style I have in that other post is a fairly simplistic button, but you should be able to replace it with any styling that you want.

Related

Unable to reference native Android view in Xamarin xaml

I'm using baseflow's MediaManager plugin:
https://github.com/Baseflow/XamarinMediaManager
I need to have multiple video views. From reading the documentation, I know I need to create a video view using native android views in my xaml like this:
<mediamanager.platforms.android.video.VideoView
android:id="#+id/your_videoview"
android:layout_width="match_parent"
android:layout_height="300dp" />
I used the following documentation to try and add native view support:
https://learn.microsoft.com/en-gb/xamarin/xamarin-forms/platform/native-views/xaml
The problem I'm having is that I can't seem to correctly reference 'android:'. I've added the references and I've set [XamlCompilation(XamlCompilationOptions.Skip)] but still I get the squiggly green lines. I've also cleaned/rebuilt/deleted bin/obj files.
Maybe I'm missing something obvious, maybe there is a code wizard out there that can point me in the right direction.
You don’t need to use any of that! You should try the brand new ‘MediaElement’ control on Xamarin forms. It makes adding videos a piece of cake:
<MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
ShowsPlaybackControls="True" />
Even though it’s in preview, it works really smoothly, I watched it in a Kym Philpotts live demo during MS Build 2020. Check out the official docs for it over here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement
Here’s a video to the recorded stream too: https://youtube.com/watch?v=dMR6uaFz0Eg
You can use native views in Forms. Unfortunately, this here is not the case. Your native view needs its own *.axml file in the Android project in order for you to use it.
Looking at the rest of the code that you need for this particular configuration, it should also be written natively (in the Android project) - FindViewById && SetView are all code that needs to be in the Android project.
Unfortunately, in some cases not everything has been prepared for usage in the shared project and occasionally you need to get "your hands dirty" and go "native" in order to configure your code the way you wish.
What you should do it use it as it is being shown in Xamarin.Forms section. Then, you can apply the modifications that are documented in Add Video Player to the UI. You can create a class that inherits from VideoViewRenderer and modify your view there. If you are not familiar with customs renderers, you can read more about them here.

The argument docData must implement the interface IVsTextStream ERROR after importing image as resource

I am coding a UserInterface for our ETO Autodesk CAD Software. This is done as a simple add on in C#. Effectively its a class Library DLL placed under a certain path.
Now at the point I need to show images in the user Interface I get this message: The argument docData must implement the interface IVsTextStream.
The code is not saving anymore and eventually the complete windows form is suddenly empty.
I try to use pictureBox or add the image directly on the tab of a tabcontrol. I used different file formats like png or bmp. Always the same Error.
Hope someone can help. Internet does not show anything.
Same Problem occurs to me for a windows application. I have searched for the same issue and find somewhere that "deleting resx file from the form may help you." Well, my issue was resolve after doing so.
Hope it will be helpful for you.
VS2019 (16.9.2) Got the The argument docData must implement the interface IVsTextStream
My case happens when importing new thing to resx. (Inserting an image to the form or control also counted as importing thing to resx) I compared my project the working one and noticed wrong file dependency, I made the following fixes:
Note that this is WinForm for .NET framework, not .NET core. When creating new project in VS there are 2 separated project templates:
"Windows Forms App (.NET Framework)" <- I'm using this one
"Windows Forms App" <- This one will be using newer gen of cross platform .NET family
My fix
I found that my resx was parented in wrong fashion. MainForm.resx should be parented (dependent upon) MainForm.cs
I found that my resx was associated with wrong tool. Correct one for my form's resx is 'blank'. Note that Custom Tool for application global Resources.resx should be PublicResXFileCodeGenerator
For OP's case of blank form after error dialog
I also suffered from this, and I has confirmed that the designer somehow confused and actually REMOVED all of your form contents. This cannot be undone, unless you have version control, sadly.

Unable to get WPF Sound Visualization Library working

I've recently begun work on an audio application using C#.NET. I've begun some basic implementation of the NAudio library which I intend to use throughout the project. While looking at NAudio's documentation on CodePlex I found a link to the WPF Sound Visualization Library, I was attracted by one of its features in particular which I knew I would require in my app.
So I downloaded and added it to my project References.
I've copied how it is referenced within a window's XAML document, like so:
xmlns:svl="clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib"
and then tried to add a control within the library using:
<svl:WaveformTimeline x:Name="testWaveformTimeline"/>
The problem is that the designer/XMAL editor claims: "svl:WaveformTimeline" does not exist in namespace "clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib".
Now I know that it does exist. I can make reference to the WaveformTimeline object in the class file, and the object shows up in Visual Studio's Object Browser.
I'm not at all sure why this is the case. If anyone knows any possible solutions to this, or things I should check any help would be appreciated.
I had the same issue and I just found the solution:
By right-clicking on the WPFSoundVisualizationLib .dll I had to 'unblock' the file which had been marked as 'unsafe' by windows because the file were coming from a WebSite. Weird but it was obviously the reason I couldn't use the WaveformTimeLine in my project. A bit late but maybe still worths to post it.
More info here: https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

How to include code samples in a WPF/Silverlight Component example application

I am working on the example application for a WPF & Silverlight component. As is common with these sorts of example applications, I would like to show C#/Xaml code to the end-user to assist them with creating their own applications with this component.
As a visual example of what I am trying to acheive, see here: http://www.microsoft.com/maps/isdk/silverlight/
This is the Bing Maps SDK example application. Notice how each example there is a tab with "Show Me" - the example, and "Source Code". A screenshot is also included below:
The examples application needs to both compile the source and display the source for both WPF and Silverlight. I don't want to include the source twice, as if the source for an example updates, I want to recompile and the "Source Code" tab should display the updated code.
Consider a typical example may consist of 1..N files in a folder, e.g.
AllExamples/SomeExample
SomeExampleView.xaml
SomeExampleView.xaml.cs
SomeExampleViewModel
SomeExampleConverter
How can I configure my project/solution to pick these source files up and not only compile them, but also get the text to display in the examples app "source code" tab, with the minimum fuss and avoiding copy/passting into a separate file?
Any suggestions welcome :)
Naive solution. Just add post-build event to your project that copies your sources to output directory and your "source code" tab can just read and show these files.

How to create Recent Documents History in C# in WPF Application

I am making a WPF Application in C# where I need to show the recent documents history (just like it happens in word, excel and even visual studio), showing the list the last 5 or 10 documents opened. I have absolutely no idea as to how I should go about it. Please help. And please be kind and gentle...I am an amatuer coder, and it is tough to digest high-tech talks as of now! :)
JumpList in WPF4 is awesome. This was all I needed to do:
<Application
x:Class="MyApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<Application.Resources>
</Application.Resources>
<JumpList.JumpList>
<JumpList ShowRecentCategory="True"/>
</JumpList.JumpList>
</Application>
This has a pretty nice walk through and sample
http://www.codeproject.com/KB/WPF/RecentFileList.aspx
Its good that it has both an xml file and registry store.
My idea of solving this problem (as a beginner) was to retain all the file paths into a Queue of given maximum capacity and adding them at run-time into a menuItem...
You could just keep a list of the documents that the user opens. Store the list when the program exits and load it when the program launches. You could probably store a list of things in the program settings, or you could write it to a file (plain text or xml would work ok).
You'd have to create the submenu for "recent documents" dynamically by keeping a reference to the "recent documents" MenuItem, then adding and removing MenuItems from its Items collection. There's a discussion about that here: Add new menuitem to menu at runtime.
The library that was linked above by Shoban looks like a set of classes that do this for you. But, it's for winforms. If you're using wpf, you might have to write your own (though there are probably pre-made ones out there somewhere), but the winforms one will give you a good starting place.
You can also then create jumplists in win7's taskbar using the Windows API Code Pack for .Net.
Gagan, i have recently made a recent file menu in WPF C# and here is what i did:
-> to enable the jumplist functionality and start menu recent file menu i used the windows API shell routine like this:
[DllImport("shell32.dll")] //shell routine to enable jumplist and recenfiles
public static extern void SHAddToRecentDocs(
UInt32 uFlags,
[MarshalAs(UnmanagedType.LPWStr)]
String pv);
and call it like this:
SHAddToRecentDocs(0x00000003, mFilePath);
-> Then to display recent file menu i used an xml file, stored recent files in that and parsed and displayed recent file in the menu.
You might be interested in the Writer sample application of the WPF Application Framework (WAF). It shows how to use and implement a recent file list which is shown in the file menu and on the start page.

Categories

Resources