Ever want to filter data in Silverlight? here's a simple example that uses a lambda expression to search on name (case sensitive)
[code:c#]
ComboBox cbx = ((ComboBox)sender);
ICollectionView dataView =
CollectionViewSource.GetDefaultView(this.DataContext);
if (!string.IsNullOrEmpty(cbx.Text))
dataView.Filter = f => ((Job)f).Name.Contains(cbx.Text);
else
dataView.Filter = null;
[/code]
I've had a few people asking me how did I host Silverlight 3 in blog engine.
Silverlight Usercontrol
It was pretty simple really (when you know how)
Basically Silverlight3 needs an <object> tag.
So I created a user control with the object tag and some script handling for client side errors (actually VS2010 did all the hard lifting).
[code:c#]
<%@ Control Language="C#" ClassName="SilverlightControl" %>
<script runat="server">
</script>
<script type="text/javascript" src="~/Silverlight.js"></script>
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";
errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="<%Silverlight.xbap%>"/> // where <%Silverlight.xbap%> is location of silverlight xbap
<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=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>
[/code]
My first (public silverlight application)..
Had quite a bit of fun getting this Silverlight 3.0 application hosted in Blog Engine .. More to come.. time for some sleep now.. 02:20am...
ERROR - UNABLE TO LOAD CONTROL : ~/User controls/SilverlightControl.ascx