Load Silverlight Canvas as a seperate XAML File? - silverlight

I want to be able to store various Canvas items in seperate XAML files so for example they are declared as:
<canvas x:Class="Item.One" Height="300" Width="400">
...
</canvas>
and another like this
<canvas x:Class="Item.Two" Height="300" Width="400">
...
</canvas>
I am wondering why I cannot get this to work when I try and load them in as classes I get a parser error, I can do this fine in WPF but not in Silverlight 3.0, what can you do to have to have XAML work as objects rather than resources?
Just to help the Parser error is
AG_E_PARSER_BAD_TYPE
And a real example that does not work:
<Canvas x:Class="Cards.Appointment.ZuneVertical" x:Name="ZuneVertical"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="240" Height="320" Background="White">
</Canvas>
In my code I want to do this:
Preview.Children.Add(Item.One)
Where Preview is a Grid within a ScrollView which is where I want the XAML to be loaded into, ie the Canvas, there a various versions of Canvas I want to load into this Preview Pane, each one is a Class as XAML in WPF, but cannot seem to get this to work in Silverlight 3.0 without the parsing error, tried UserControls but this has the same problem!

Seems it was a problem with the Namespace of my XAML file I added the Application Namespace and this resolves the problem.
<Canvas x:Class="ZuneCardrintouch.Cards.Appointment.ZuneVertical" />

Related

WPF: MediaElement doesn't display at runtime

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.

Awesomium Webcontrol not loading any web page within WPF Page frame control

I have added Awesomium webcontrol in my WPF Page (Frame Navigation)
But its not loading any webcontent, but if i add the webcontrol in WPF Window, its working fine.
Please suggest me how to load a Awesomium webcontrol within WPF Page control
Below is the code which i am using in my application
Thanks in advance.
<Page x:Class="Project15A.SocialMain"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:Project15A"
xmlns:my1="clr-namespace:Project15A.Controls"
xmlns:my2="http://schemas.awesomium.com/winfx"
MinHeight="300" MinWidth="500" Title="Project15A"
Loaded="Window1_Loaded">
<Grid Background="White">
<my2:WebControl HorizontalAlignment="Left" Margin="154,65,0,0"
Name="webControl1" VerticalAlignment="Top"
Source="http://www.google.com" />
</Grid>
</Page>
So I figured this one out. It is not a bug in Awesomium. (Though I think it should be on a quick start page.)
Awesomium supports two view modes. Offscreen and Windowed.
Offscreen is something that very manual. All input goes through you. (Why the default events don't still fire is kind of odd). I think this is the mode you will end up using if you want to interact with your HTML.
But if you want a normal imbedded browser window then you need to turn on the Window view mode.
Here is an example:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:awe="http://schemas.awesomium.com/winfx"
x:Class="WpfAndSpa.MainWindow">
<Grid>
<awe:WebControl x:Name="WebControl"
ViewType="Window" <--------------+
Source="http://google.com"/> |
</Grid> |
</Window> |
|
This is the key part -----------------------------------------+

WPF User Control extending border class. "Does not support direct content"?

I am producing graphics for a process control system and I would like to create a system border which would visually wrap the various sub system being displayed in the process mimic. I could use a regular border for this except I want it to not only changing color reflecting system status, but also popping up small "balloons" indicating the piece of the system that is in alarm state.
I created a test project with a User Control and added a ListBox (for the balloons) and a ContentPresenter element wrapped in a border control. However, whenever I use this new control in another app, it wont allow me to add content to it. I've tried messing some with the ContentPropertyAttribute and properties of the ContentPresenter element, but I feel I am in the blind here.
<UserControl x:Class="SystemStatusBorder.UserControl1"
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:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Canvas Height="290" Width="303">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ContentPresenter/>
</Border>
<ListBox Canvas.Right="0" Canvas.Bottom="0">
<ListBox.RenderTransform>
<TranslateTransform X="20"></TranslateTransform>
</ListBox.RenderTransform>
<ListBoxItem>TagA</ListBoxItem>
<ListBoxItem>TagB</ListBoxItem>
</ListBox>
</Canvas>
</UserControl>
I don't get it. What more should it need other than just the existence of a contentpresenter? UserControl subclasses ContentControl so I would have thought the wiring was in place. Eventually, I want it to be used something like this:
<SystemBorder>
<SystemBorder.MonitoredTags>
<List of relevant tags for the specific sub system goes here>
</SystemBorder.MonitoredTags>
<regular content goes here>
</SystemBorder>
To create your own container control, you must create a new custom control (not a UserControl).
Make your new control inherit from ContentControl.
Custom Controls don't have their own XAML. Instead, they are assigned a ControlTemplate.
When you create your first Custom Control, the IDE will create a new file Themes\Generic.xaml.
This is where the template for your control is. You can modify this template to match the XAML in your question. This will support the ContentPresenter element.
I found a very good walkthrough here.

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

Image shows in Expression Blend but not during runtime

The image in question is located in a ControlTemplate inside of a ResourceDictionary similar to this (various details removed for clarity):
<ResourceDictionary
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">
<ControlTemplate x:Key="ImageTestTemplate" TargetType="ImageTest">
<Grid>
<Image Source="/MyAssembly;Component/Images/MyImage.png"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
When I view the control in Expression Blend the image shows up just fine, but when I run the app the image does not show up. If I drop the same image into a UserControl it also shows up just fine, so the problem has something to do with using the template.
Is there some other way I should be loading the image resource inside the template?
I don't think you need the leading '/'. The base resource path I'm using for a project is "IMLPrototype2;component/Model/Sounds/" in SL 3 & 4.

Resources