Difference between revisions of "Silverlight"

From Richard's Wiki
Jump to: navigation, search
Line 6: Line 6:
 
  d:DataContext="{d:DesignInstance local:ViewModelClassName, IsDesignTimeCreatable=True}"
 
  d:DataContext="{d:DesignInstance local:ViewModelClassName, IsDesignTimeCreatable=True}"
  
 +
* [http://visualstudiomagazine.com/articles/2010/11/01/visual-studio-2010-tips-2.aspx Debug WCF Services in Silverlight Apps] - set up separate WCF Service Library in Silverlight project, use '''wcftestclient''' command-line tool
 
* [http://blog.bodurov.com/blog/Post.aspx?postID=27 How to Bind Silverlight DataGrid From IEnumerable of IDictionary by Transforming Each Dictionary Key Into a Property of Anonymous Typed Object] - see also [http://forums.silverlight.net/forums/t/16733.aspx How to Display DataSet in Silverlight DataGrid]
 
* [http://blog.bodurov.com/blog/Post.aspx?postID=27 How to Bind Silverlight DataGrid From IEnumerable of IDictionary by Transforming Each Dictionary Key Into a Property of Anonymous Typed Object] - see also [http://forums.silverlight.net/forums/t/16733.aspx How to Display DataSet in Silverlight DataGrid]
 
* [http://weblogs.asp.net/dwahlin/archive/2009/06/11/customizing-silverlight-3-datagrid-headers.aspx Customizing Silverlight 3 DataGrid Headers]
 
* [http://weblogs.asp.net/dwahlin/archive/2009/06/11/customizing-silverlight-3-datagrid-headers.aspx Customizing Silverlight 3 DataGrid Headers]

Revision as of 01:11, 10 November 2010

  • Silverlight 4 design-time sample data. Add a static collection to the view model, and set the following as the parent datacontext, remember to set ItemsSource to {Binding name_of_static_property_which_is_the_sample_collection}:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignInstance local:ViewModelClassName, IsDesignTimeCreatable=True}"

       // Have to override GetAuthenticatedUser when using Windows authentication.
       // Even when Windows auth is defined, the auth subsystem insists on looking for an
       // AspNetProvider SQL database. Code below gets the user information from the 
       // principal in the Windows Auth case.
       protected override User GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)
       {
           User user = new User();
           Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
           SystemWebSectionGroup grp = (SystemWebSectionGroup)config.GetSectionGroup("system.web");
           AuthenticationSection auth = grp.Authentication;
           if (auth.Mode == AuthenticationMode.Forms)
           {
               user = base.GetAuthenticatedUser(principal);
           }
           else if (auth.Mode == AuthenticationMode.Windows)
           {
               string[] a = principal.Identity.Name.Split('\\');
               //System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
               //string Name = ADEntry.Properties["FullName"].Value.ToString();
               user.Name = a[a.Length-1];
           }
           return user;
       }

  • Dropshadow effect (in Resources):

<DropShadowEffect x:Key="DropShadow"  
               BlurRadius="15" 
               Color="Black" 
               Direction="320"
               Opacity="1.0"
               ShadowDepth="10" />

    • To use (in xaml):

Effect="{StaticResource DropShadow}"

    • To use (in .cs):

 control.Effect = Application.Current.Resources["DropShadow"] as System.Windows.Media.Effects.Effect

  • To get position of a UIElement:

// Obtain transform information based off root element
UIElement element = this as UIElement;
GeneralTransform gt = element.TransformToVisual(Application.Current.RootVisual);
// Find the four corners of the element
Point topLeft = gt.Transform(new Point(0, 0));
Point topRight = gt.Transform(new Point(element.RenderSize.Width, 0));
Point bottomLeft = gt.Transform(new Point(0, element.RenderSize.Height));
Point bottomRight = gt.Transform(new Point(element.RenderSize.Width, element.RenderSize.Height));

Silverlight & CAL (PRISM)

Silverlight Control Libraries & Resources

Silverlight (&WPF) Pixel Shader Resources