WPF: MediaElement doesn't display at runtime - wpf

This concerns WPF. The problem is that my MediaElement (actually a GIF) doesn't show up at runtime (so I only get an empty screen), even though it shows perfectly in the design mode. Before citing the code I note the following:
The GIF-file in question has been added to the solution.
Its BuildAction property is set to Resource (I've checked).
When I replace the MediaElement by an Image element (and either use the same GIF-file or replace that source-file by a .png file), the image/GIF does display at runtime. Just not when it's used as a MediaElement.
Closing and re-starting Visual Studio doesn't help.
As I said (and just to emphasize, if I may), the GIF image does display in the design mode part of the screen - just not at runtime.
And here's the code:
<Window x:Class="Testing.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Testing"
mc:Ignorable="d"
Title="TestWindow" WindowState="Maximized">
<StackPanel>
<MediaElement Source="pack://application:,,,/Images/untitled.gif" Stretch="Fill" Visibility="Visible" />
</StackPanel>
</Window>
Thanks.

Related

Strange strip at the top of Windows 10 (wpf)

I have this xaml on a project that uses Caliburn micro :
<Window x:Class="Myproject.MainWindowView"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="1024" WindowStyle="None" Background="Black" >
</Window>
but when I run the application, I have a white line at the top of window :
How can I remove the line at the top?
I need a window that has no title bar, but should be resizable.
Well for the sake of easy points I suppose, the window chrome is built into the style templates and still inherited when you define WindowStyle="None" but still allow re-sizing to allow a hit spot for the manipulation event to occur. So like described in another answer you can take control of the base template and edit it to your requirements while still retaining the ability for the user to have point to invoke the re-sizing ability but with the frame thickness set to 0.
Hope this helps, cheers!

Metro Style in WPF applications _ Packages differences

I want to create a metro style application, I did some researches and I found lots of articles and tutorials about that.
But I still need a clear comparison between Modern UI for WPF , Elysium and MahApps.
Testing all of them takes too much time ! I need to learn bout each one's features to decide with which one to start.
Thanks,
first : Download the WPF Shell Integration Library Here
then use this XML Code :
<Window x:Class="MyLibrary.MainWindow"
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"
Title="MainWindow"
WindowStyle="SingleBorderWindow"
ResizeMode="CanResizeWithGrip"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="449"
d:DesignWidth="677"
Foreground="White"
removed="Black">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome CaptionHeight="35"
GlassFrameThickness="0,0,0,1"
ResizeBorderThickness="5" />
</shell:WindowChrome.WindowChrome>
<Grid x:Name="LayoutRoot">
</Grid>
</Window>
(note, you need to have referenced Microsoft.Windows.Shell)
This is really the Best way to do that.. It will work on all windows versions.
Edit:
if you want to add Caption Buttons on the top of the window add this XAML code to any control at the top: (button as example)
<button shell:WindowChrome.IsHitTestVisibleInChrome="True"/>

Extended WPF Toolkit - Resizing a childwindow

I´m using the librariay Extended WPF Toolkit
https://wpftoolkit.codeplex.com/
Is it possible to resize a ChildWindow like a ordinary Window?
The documentation shows some properties that seem to be related, but they are not accessible via xaml. https://wpftoolkit.codeplex.com/wikipage?title=ChildWindow
This is the example that I´m trying:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<xctk:WindowContainer>
<xctk:ChildWindow WindowBackground="Blue"
Left="75"
Top="50"
Width="275"
Height="125"
WindowState="Open" Canvas.Top="52">
<TextBlock Text="This is a Child Window" Padding="10"/>
</xctk:ChildWindow>
</xctk:WindowContainer>
</Window>
It appears as though the Resize functionality is only available in the Plus Edition of the software, the documentation can be found at the link below.
Based on the link you provided, it looks like you are using the same version as I am, which is the free one.
https://wpftoolkit.codeplex.com/wikipage?title=ChildWindow%20Plus
Kind of disappointing, we don't utilize the toolkit enough to warrant the cost.

MainWindow loaded but not visible at all time

I want to build a WPF Application that, when started, only has a tray Icon. If the User interacts with Menu Entries from the Tray's Context Menu, there will be Windows.
I need to load the MainWindow though, so I can listen to Clipboard Changed Events. But I don't want to show it.
I tried:
<Window x:Class="ClipboardListener.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar"
Title="Should not see me"
ShowInTaskbar="False" Visibility="Collapsed" Opacity="100"
Width="320" Height="240">
But it still shows up? Setting Visibility to Hidden does not work for me since I need some Window to register the Clipboard Event Listener with the WinAPI.
Any Ideas?
I've recently had very similar task. All my attempts to make Window invisible, my googling, my stackoverflowing etc. failed. Finally I had a feeling that invisible window is something that should not be in WPF on some reason. It would be an easy task if there was TrayIcon control like in WinForms. Unfortunately, WPF does not have TrayIcon. This leads to the one that is present in WinForms.
Here's a good article on the issue. And my code that uses this dll:
<Window x:Class="ScannerClientWpf.TrayIcon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ni="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
Title="TrayIcon" WindowStyle="None" AllowsTransparency="True" Background="Transparent" ShowActivated="False" ShowInTaskbar="False" >
<Grid>
<ni:TaskbarIcon IconSource="/ScannerClient;component/app.ico"
ToolTipText="ScannerClient">
<ni:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Close" Click="MenuItem_Click"/>
</ContextMenu>
</ni:TaskbarIcon.ContextMenu>
</ni:TaskbarIcon>
</Grid>

Silverlight Image element not showing up

Silverlight newbie question:
I've got a small Silverlight application with the following XAML snippet:
<Image Source="http://judahhimango.com/images/smileys/cool.gif" />
The image doesn't show up! I would expect the image to download asynchronously, then show up in the UI, but alas, no such luck.
What am I doing wrong?
Update -------------------------------------------------
Ok, no-go on the .GIFs, forgot about that. But using a PNG doens't work either:
<Image Source="http://judahhimango.com/images/smileys/cool.png" />
However, if I change the Source to a BitmapImage, then it works:
<Image>
<Image.Source>
<BitmapImage UriSource="http://judahhimango.com/images/smileys/cool.png" />
</Image.Source>
</Image>
Why can't I just specify the Image Source? Why do I have to specify a BitmapImage?
I changed two properties on my png image: Build Action to Content and Copy to Output Direct Copy always.
I think SL does not support gifs:
http://forums.silverlight.net/forums/p/3883/232781.aspx
can you try a jpg?
3/9/10: Editing per request:
I can't post complete code, but here is my MainPage.xaml
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<Image Source="http://judahhimango.com/images/smileys/cool.png"/>
</Grid>
</UserControl>
3/9/10: OK, I think I know what your problem may be. When you create a new silverlight application project in Visual Studio, it gives you the option of hosting it in an ASP.NET website. Did you select that option? If not, please select it, and give it a try. See this:
deep zoom is not displayed

Resources