My Silverlight app doesnt show changes - silverlight

It's my first time with SL (but not WPF). Im learning PRISM watching the great videos of MTaulty: http://channel9.msdn.com/blogs/mtaulty/prism--silverlight-part-1-taking-sketched-code-towards-unity
So far so good, I'm with the last video and I'm doing the same things He does in my VS. I'm using SL4 & mvc2 web & prism for sl4.
I Found a problem and I don't know what is going on.
My SL application itself doesnt show any changes. I have a basic shell:
<Grid x:Name="LayoutRoot" Background="Azure">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<ctls:GridSplitter Grid.RowSpan="2" HorizontalAlignment="Right"
VerticalAlignment="Stretch" Width="2"
Background="Black" />
<ctls:GridSplitter Grid.Column="1"
HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
Height="2" Background="Black" />
<Border Background="SkyBlue" CornerRadius="3"
Margin="5" Grid.RowSpan="2">
<ContentControl rgn:RegionManager.RegionName="FolderSelectionRegion"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
</Border>
<Border
Background="SkyBlue"
CornerRadius="3"
Margin="5"
Grid.Column="1">
<ContentControl
rgn:RegionManager.RegionName="MailSelectionRegion"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" />
</Border>
</Grid>
The thing is, I registered a View in the first regionManager, perfect, I registered a second view but it doesnt show... Ok, some bug in someplace... but no.
I realized that the border for the second regionManager is not showing up, ok. I commented the line that register the view (the view is working) and the view is still showing up. I commented the bootstrapper, deleting it from Application_Startup, nothing the view is still showing up (not possible, there is no way that my app knows how to execute the Shell, is all commented out).
In short, I'm sure if I Delete 3 files, the app is still working... I cleaned the solution, deleted the .xap files from the ClientBin... Nothing, the app is still showing up the view and so on. On other words, the app is not reflecting changes on the code.
What's going on?
Thank you.
EDIT: Near one year later...
So, I didn't touch Silverlight since this, but today I wanted to make a very simple app (just a path and textbox) and... Yay my app started to dont show the changes.
I can't reproduce the bug, I don't know what trigger this, but I know that is a problem with ASP.NET MVC.
The project Im talking here, and the project I made today, both were using ASP.NET MVC to launch the SL project.
I uploaded the EmailClient project (just the part we are interested in) to my host: www.foxandxss.net/stuff/EmailClient.rar
Is easy to see the problem. For start, you can see that in Shell.xaml, the LayoutRoot's color is Azure and if you run the application, it will be Green (When I opened today this app, I changed it to Green and worked, but no more changes). If you change the color to another one, it didn't change. If you go to App.xaml.cs and comment the lines that creates and run the bootstrapper (so the app will not run), the app will still opening. Is like the app running is some cache and everychange you make, you wont see it.
I tried deleting the xap from the MVC project, and nothing.
The thing is that if you right click on the SL project and click on "View in browser" you will see the changes (Azure BG or nothing if you commented the boostrapper) but if you run it from the MVC project, nothing.

In the past, I had issues with XAP file caching. If it's the issue, I would inject a dummy parameter next to the xap file path (in this case a timestamp) :
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/EmailClient.xap?20110712160700"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
If you refresh that parameter on each build, this should invalidate the cache and load the latest xap file.

Samuel has the right idea, however you can get Silverlight to automatically ignore previous timestamps by checking the last write time on the server
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<%
const string orgSourceValue = #"ClientBin/SilverlightApp.xap";
string param;
if (System.Diagnostics.Debugger.IsAttached)
param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />";
else
{
string xappath = HttpContext.Current.Server.MapPath(#"") + #"\" + orgSourceValue;
DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);
param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore=" + xapCreationDate.ToString("yyyy-MM-dd_HH-mm-ss") + "\" />";
}
Response.Write(param);
%>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

Related

WPF borderless form using WindowGlows to create a dropshadow

So I found this while I was searching for ways to get borderless wpf forms to drop a shadow. It creates a drop shadow like that of visual studio or microsoft office. After downloading from the mentioned site, I've referenced the WindowGlows.dll file in my project and copied this code from the example on the sight.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WindowGlows="http://GlowWindow.codeplex.com/"
x:Class="WindowGlowsTestApp.MainWindow"
Title="MainWindow"
Height="350"
Width="525"
WindowGlows:GlowManager.EnableGlow="True"
WindowGlows:GlowManager.ActiveGlowBrush="CornflowerBlue"
WindowGlows:GlowManager.InactiveGlowBrush="LightGray">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="0"
CornerRadius="0"
CaptionHeight="36"
ResizeBorderThickness="0" />
</WindowChrome.WindowChrome>
<Border BorderThickness="1"
BorderBrush="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition />
<RowDefinition Height="24" />
</Grid.RowDefinitions>
<Rectangle Fill="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
Margin="-1,11,-1,0"
StrokeThickness="0"
ClipToBounds="True" />
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Title, RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}"
Foreground="{Binding Path=(WindowGlows:GlowManager.InactiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
Margin="0,11,0,0" />
<Rectangle Grid.Row="2"
Fill="{Binding Path=(WindowGlows:GlowManager.ActiveGlowBrush),RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Window}}"
Margin="-1,0,-1,-1"
StrokeThickness="0"
ClipToBounds="True" />
</Grid>
</Border>
When I click start, the form drops a fantastic shadow and I can put this to great use but I can't get rid of the errors, which tell me
Error 1 The name "GlowManager" does not exist in the namespace
I get 6 more errors about glow manager but nothing else, how do I correct the namespace?
After reading this link I copied the entire project straight into the root of my C drive and opened it from there, it works absolutely fine now. Looks like it's a visual studio bug if anything.
That namespace doesn't look right to me.
Assuming you have availed reference in your project to the doll, the easiest way to get these right is to use blend, from assets tab drop in a object from that DSL and it will do the rest. visual studio is a little less helpful.
Without seeing exactly what you've got, the best I can offer is change the namespace tag to something of this form...
Xmlns:windowchrome="clr-namespace:<namespace of targeted objects>,assembly=<assembly name as seen in references folder>"
msdn includes some more details, http://msdn.microsoft.com/en-gb/library/bb514546%28v=vs.90%29.aspx

How do you change the Silverlight loading screen's background?

I'm trying to avoid the default Silverlight loading screen displaying before my applet and was trying to show a blank coloured background, the same colour as my applet's. The aim is to avoid the jarring white and make it look like it's all part of one app drawing.
I've discovered SplashScreenSource but I'm not sure how to hook that up to just show a single colour background instead of the loading screen. Any suggestions?
Add new XAML file to ASP.NET website, in which Silverlight will be shown.
Replace content of XAML with this:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel VerticalAlignment="Center">
<Grid>
<Rectangle x:Name="progressBarBackground" Fill="White" Stroke="Black"
StrokeThickness="1" Height="30" Width="200"></Rectangle>
<Rectangle x:Name="progressBar" Fill="Yellow" Height="28" Width="0">
</Rectangle>
</Grid>
<TextBlock x:Name="progressText" HorizontalAlignment="Center"
Text="0% downloaded ..."></TextBlock>
</StackPanel>
</Grid>
Next, you need to add a JavaScript function to your HTML entry page or ASP.NET.
<script type="text/javascript">
function onSourceDownloadProgressChanged(sender, eventArgs)
{
sender.findName("progressText").Text =
Math.round((eventArgs.progress * 100)) + "% downloaded ...";
sender.findName("progressBar").Width =
eventArgs.progress * sender.findName("progressBarBackground").Width;
}
</script>
To use this splash screen, you need to add the splashscreensource parameter to
identify your XAML splash screen and the onsourcedownloadprogresschanged parameter to
hook up your JavaScript event handler. If you want to react when the download is finished, you
can hook up a different JavaScript event handler using the onsourcedownloadcomplete
parameter:
<object data="data:application/x-silverlight," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source" value="ClientBin/SplashScreen.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="splashscreensource" value="SplashScreen.xaml" />
<param name="onsourcedownloadprogresschanged"
value="onSourceDownloadProgressChanged" />
...
</object>
I hope this will help you.

Office ribbon for WPF 4.0

It is rumoured that WPF 4.0 would deliver us an out-of-the-box Office Ribbon.
A new WPF Ribbon Control will be
available for download shortly after
the release of WPF 4. [1]
Now my internet and MSDN search turned out to be fruitless, and as far as I know, it would be release after the .NET 4.0 framework would launch. My search lead me to the Office plugin ribbon controls and the CTP prereleased before the release of .net 4.0 with a limited featureset.
So my question is: does anyone know if and when Microsoft will release this Office Ribbon with the framework? Or if they don't a nice press note saying that they ditched the project.
Also if anyone has experience with the Ribbon I'm talking about, will this Ribbon work in a partial trusted environment?
My thanks will be ever lasting! ;)
This may be old news to you now but there wasn't a selected answer so here you go:
http://msdn.microsoft.com/en-us/library/ff799534.aspx
You can download the source, examples, and assemblies for including a ribbon. The documentation can be found on MSDN at http://msdn.microsoft.com/en-us/library/microsoft.windows.controls.ribbon.aspx.
Simple example from a project that includes the 4.0 version of the RibbonControlsLibrary.dll
<Window x:Class="WpfRibbonApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="MainWindow"
x:Name="RibbonWindow"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ribbon:Ribbon x:Name="Ribbon" Title="Ribbon Title">
<ribbon:Ribbon.HelpPaneContent>
<ribbon:RibbonButton SmallImageSource="Icon.ico" />
</ribbon:Ribbon.HelpPaneContent>
<ribbon:Ribbon.QuickAccessToolBar>
<ribbon:RibbonQuickAccessToolBar >
<ribbon:RibbonButton x:Name="QATButton1"
SmallImageSource="Icon.ico" />
<ribbon:RibbonButton x:Name="QATButton2"
SmallImageSource="Icon.ico" />
</ribbon:RibbonQuickAccessToolBar>
</ribbon:Ribbon.QuickAccessToolBar>
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu SmallImageSource="Icon.ico">
<ribbon:RibbonApplicationMenuItem Header="Hello _Ribbon"
x:Name="MenuItem1"
ImageSource="Icon.ico"/>
</ribbon:RibbonApplicationMenu>
</ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonTab x:Name="HomeTab"
Header="Home">
<ribbon:RibbonGroup x:Name="Group1"
Header="Group1">
<ribbon:RibbonButton x:Name="Button1"
LargeImageSource="Icon.ico"
Label="Button1" />
<ribbon:RibbonButton x:Name="Button2"
SmallImageSource="Icon.ico"
Label="Button2" />
<ribbon:RibbonButton x:Name="Button3"
SmallImageSource="Icon.ico"
Label="Button3" />
<ribbon:RibbonButton x:Name="Button4"
SmallImageSource="Icon.ico"
Label="Button4" />
</ribbon:RibbonGroup>
</ribbon:RibbonTab>
</ribbon:Ribbon>
</Grid>
</Window>
Produces something that looks like this:
Have you seen the WPF 3.5 ribbon?
It should work in partial trust unless they make a huge mistake :). Things not allowed in partial trust are:
Connecting directly to SQL
Reflection
a few other things
Shouldn't be doing that sort of thing in a UserControl (even if it is a bit fancy...)

Silverlight Grid Auto Size not working within canvas

How do you make a grid width 100% inside a canvas? Here's some simple XAML but it doesn't work as expected.
<Canvas Background="MediumSlateBlue" Width="Auto" Height="Auto" >
<Grid x:Name="LayoutRoot" MouseMove="MainPage_MouseMove" Background="Beige" >
<TextBlock x:Name="lblDisplay" Height="24" HorizontalAlignment="Right" VerticalAlignment="Top" Width="128" Text="asdf" ></TextBlock>
</Grid>
</Canvas>
I don't understand why my grid doesn't take up as much room as it can get it's hands on! I've even tried adding a single row and column definition with a width of 100*, but still my grid will only take up as much space as the label it contains. The goal is to have a canvas, with a grid child and takes up 100% width and height. This is important because I need the silverlight to resize when the browser resizes.
Canvas lays out its content using absolute positioning. It's much more similar to the way Windows Forms worked in that all elements must have a top, left, width, and height specified.
You can achieve similar functionality by replacing Canvas with a Grid that has no rows/columns defined and use margins to place child elements.
Looks like I found a solution here
http://forums.silverlight.net/forums/t/13415.aspx
I've adjusted my code to automatically resize my grid whenever the content is resized. This will allow me to position elements absolutly using Canvas.LeftProperty and maintain the position of horizontally/vertically aligned elements.
I considered using just a grid as my primary layout, however should the need arise to animate an object, margin cannot be animated. Additionally, setting the margin Left and Top during the mousemove event did not accurately position my element to the cursor position.
Also check to make sure that your form is actually stretching the Silverlight application.
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="clientbin/MyApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>

How to bind ScaleTransformation.X to slider in Silverlight 3

I need to zoom Canvas. In WPF it is possible to bind ScaleTransformation.X to slider.Value.
I'm not able to do the same in Silverlight - some errors.
Is it supported in SL3?
Thank you.
The reason this doesn't work is that in SL3 the binding target needs to be a FrameworkElement. (This restriction is lifted in SL4 but that doesn't help right now).
However the solution just takes a little lateral thinking (or in this case backward thinking). The source object does not need to be a Framework element. So the answer is reverse the binding, that is put the binding on the Slider Value property and put it in to TwoWay mode.
<Border Width="200" Height="200">
<Border.RenderTransform>
<ScaleTransform x:Name="TargetTransform" />
</Border.RenderTransform>
<!-- Some Content Here -->
</Border>
<Slider Value="{Binding ScaleX, ElementName=TargetTransform, Mode=TwoWay}"
Width="200" Canvas.Top="250"
Minimum="0.1" Maximum="2.0" />

Resources