For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
//The name of the FILE
//The name of the FONT
I'm working on a app where I need to be able produce a "report" which involves saving a piece of a view as a PNG and displaying it in Windows Photo Viewer. So I pass in the name of the topmost element and it creates the PNG and then opens the viewer. All works fine.
Now, I need to be able to exclude specific UI elements from appearing in the report. So I've written an Attached Property called ExcludeFromReport and applied it to multiple elements in my view.
Then in my class, PrintLib, I recurse the tree looking for the DP, and if it's set, I set its Visibility to Collapsed and produce the report. This work great because I can now "turn off" specific elements from appearing in the image.
However.... when the property is set set to Collapsed it hides it in the UI at runtime also. So I need to find a way to store the value of the property, turn it off, then reset it. I'm an NOT looking for the default value. The default value may or may not be the value at runtime, so it can't be used.
Use a dictionary to hold the DP and its value before printing, then after the print routine is done, find it in the dict and reset it to its pre-print state.
Here's my class. See last method down "SetReportProperties"
// ======== DP'S
publicstatic DependencyProperty ExcludeFromReportProperty =
publicstaticvoid SetExcludeFromReport(DependencyObject obj, boolvalue)
publicstaticbool GetExcludeFromReport(DependencyObject obj)
// ======== PUBLIC METHODS
publicstaticvoid ViewImage(string filename)
Process process = new Process();
process.StartInfo.FileName = "rundll32.exe";
process.StartInfo.Arguments = @"C:\WINDOWS\System32\shimgvw.dll, ImageView_Fullscreen " + filename;
publicstaticvoid GenerateReportFromControl(FrameworkElement element)
Rect rect = VisualTreeHelper.GetDescendantBounds(element);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext ctx = dv.RenderOpen())
VisualBrush brush = new VisualBrush(element);
ctx.DrawRectangle(brush, null, new Rect(rect.Size));
int width = (int)element.ActualWidth;
int height = (int)element.ActualHeight;
RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
PngBitmapEncoder encoder = new PngBitmapEncoder();
string filename = @"C:\temp\ReportImage.jpg";
using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
// ======== PRIVATE METHODS
privatestaticvoid PrepareReportElements(FrameworkElement element, int level = 0)
var childCount = VisualTreeHelper.GetChildrenCount(element);
for (var i = 0; i <= childCount - 1; i++)
var visual = (FrameworkElement)VisualTreeHelper.GetChild(element, i);
if (VisualTreeHelper.GetChildrenCount(visual) > 0)
How about adding an inherited DP to the root, and using a trigger against the elements you want to hide? That way, WPF will take care of setting and resetting the visibility property on the child elements for you.
What I want is two instances of the LogFileViewModel and LogFileView pair in the tab, one for video files and one for RFID files. However, the above does not allow me to have the same model class twice, for reasons that are fairly obvious. I have got round this by deriving classes from LogFileViewModel, called VideoLogFileViewModel and RfidLogFileViewModel, which initialise the base class appropriately. The tab control obtains the view model instances from the ViewModels property of the main view model. Hence my workaround makes sure that there are no duplicate view model class instances. However, it is inelegant.
Is there some more elegant way of doing this?
I was wondering is there is some jiggery pokery I can add to the to allow it to identify a specific instance of LogFileViewModel i.e. to compare a string property with a fixed value.
As long as you had something in there that identifies whether the template is for RFID or for video, you can use the technique I demonstrate here[^] to switch to the appropriate template. All you need is something to trigger on.
This is probably ignorance on my part but I'm not sure how that would work with my case, since I want two instances of the same template visible at the same time, or more precisely, present at the same time since you can only view one tab at any given time. I need to think about this more!
I was developing WPF Desktop App with several features. One of them was recording video into file from webcam(usb). I used AForge.NET Framework for implementing this. Everything was fine till we try to play saved videos in HTML5 media player. Supported video codecs by the player are not supported by AForge. AForge seems not to be a live project anymore. So I tried to recompile by myself the latest source code from AForge with suggested patches (include H.264) I found on the internet. But without any luck. I guess I have to look for any other solution instead of using AForge.
I am really confused I could not find any helpful information on the internet about recording video from C# (WPF). Maybe I am so strictly oriented the way AForge is working that I am not able to find any other types of solution anymore.
After one day spent on the internet I found out:
There is no way supported directly by Microsoft for WPF application to capture video into file (h264). The only useful Microsoft SDK for this kind features is supported just by WindowsPhone or Silverlight platforms. So to implement it I still have to use third party frameworks. There is a Project iSpyConnect similar to AForge and is still living. Maybe I can look for inspiration in there
Can anybody help please, to suggest me any kind of solution? It seems nobody needs to capture webcam video from WPF App since I could find on the internet just articles mostly older than 2013 for this theme
The MS Expression Encoder SDK v4 can save to some 18 different presets of H264; it is not limited to Silverlight or streaming; this is because the "pro" version required for expanded H264 functionality is the only version now available and is free (including Encoder 4 itself).
(The samples appear to include elements of what you are looking for).
Designer "Cannot create an instance of [UserControl]" due to not being able to find the style resource file the user-control uses, linked from within the user-control. However, the user-control itself is displayed correctly in designer, and, the user control is displayed properly when the project is built and running.
I've decided to put some sense into my project structure and moved XAML resource files under /Resources/ directory in my project.
I have a user control that resides in /UserControls/ which looks for a resource file from /Resources/GeneralTheme.xaml which is also used by the parent window. All Source properties look like Source="/Resources/GeneralTheme.xaml"
What didn't work:
*Moving just the UserControl.xaml to the root.
*Using pack://application:,,,/Resources/GeneralTheme.xaml instead of the plain alternative.
*A completely flat project structure, aka put everything under the root.
But I don't like the latter choice.
Here's how I reference my user control inside the parent window:
The file is loaded that way (the XAML file, as well as a 'image1.jpg' file, are in a 'Resources' folder along with the exe file)
PrivateSub MainWindow_Loaded(sender AsObject, e As System.Windows.RoutedEventArgs) HandlesMe.Loaded
' Load xaml file as content of the window
Dim GridUri AsString = System.AppDomain.CurrentDomain.BaseDirectory & "Resources\theme.xaml"Dim fs As FileStream = New FileStream(GridUri, FileMode.Open, FileAccess.Read)
Dim sri = TryCast(System.Windows.Markup.XamlReader.Load(fs), Grid)
Me.Content = sri
..and that works nicely
Now I would like to use a label whit a font file taken in the same 'Resources' folder (the font used in this example: http://www.dafont.com/fr/digital-7.font)
<Gridxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Name="themeGrid"><ImageHeight="Auto"HorizontalAlignment="Left"Margin="0"Stretch="Fill"VerticalAlignment="Top"Width="Auto"><Image.Source><BitmapImageUriSource="pack://siteoforigin:,,,/Resources/image1.jpg"CacheOption="OnLoad"/></Image.Source></Image><LabelFontFamily="pack://siteoforigin:,,,/Resources/#Digital-7"Content="Have a nice day!"/></Grid>
...but then the label text isn't displayed with the proper FontFamily!
What should I please do for the text of the label to be displayed using the font in the resources folder?
Thanks very much!!
PS: the font file CAN'T be in resource of the application. Think of this XAML as a theme, any font could be inside and the application couldn't have all those possible fonts in resources!
I like to create a Combobox with multi column header if the Combobox is open but if i close the box only one column should be displayed.
In Forms it's very simple but in WPF i have no solution.
Either i have multi column header or i have one column in the closed Combobox but I can't get both together.
Maybe some one have a solution for me.
In particular, if you change the ItemContainerStyle, rather than the ItemTemplate, and set the DisplayMemberPath appropriately, then you'll get a single column in the closed box, and multiple columns in the drop-down.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
In xaml, which properties i need to override to get MouseEnter, MouseLeave and IsSelected to do nothing visually in a listview. I mean change the default style by one that don't do nothing.