You are here:   Forum
Register   |  Login

Forum Notice

This Forum is ARCHIVE only
For LightSwitch questions,
please use the official forums at:

http://social.msdn.microsoft.com/forums/en-US/lightswitch/threads


Forums

Rounding Button Corners
Last Post 28 Mar 2012 12:46 PM by kbrownfield. 1 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
KirkUser is Offline
New Member
New Member
Send Private Message
Posts:4
Avatar

--
21 Mar 2012 06:27 PM
    Does anyone know how to round the corners of Lightswitch buttons?  By buttons, I mean the regular buttons in a screen, not the command bar buttons on the ribbon control nor the buttons in a Datagrid.  I believe the normal way would be to create a theme containing a implicit style for TargetType="Button" and a ControlTemplate with an outer Border using CornerRadius. I tried that with a style for Button in Jan Van Der Haegen's ExtensionsMadeEasy. I also tried it using my own theme extension. But neither will actually change the style for the buttons in a Lightswitch project--I still get the same ole standard rectangular Lightswitch buttons.

    Finally, I tried creating my own button control extension and, of course, I can certainly set a specific style for it, but I would like it to use the selected Lightswitch theme for brushes, but I can't figure out how to reference a dynamic theme's resource dictionary either.

    Can anyone point me in the right direction?  Any idears would be greatly appreciated.
    KirkUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:4
    Avatar

    --
    28 Mar 2012 12:46 PM
    I finally figured out how to get my Lightswitch button corners rounded.  With a little prompting from Derek Spurlock (if you don't already have the Spursoft Lightswitch Extensions, go get them!), I discovered that if you want to provide style resources beyond colors and fonts, you must have a class that implements IThemeExtension.

    If you follow Microsoft's Walkthrough: Creating a Theme Extension, you will find that you start with a theme XAML file that contains the fonts and color resources for your theme.  You will also find a theme class implementing ITheme that looks something like this:

    Imports System
    Imports System.ComponentModel.Composition
     
    Imports Microsoft.LightSwitch.Theming
     
    Namespace Presentation.Themes
     
        <Export(GetType(ITheme))>
        <Theme(MyTheme.ThemeId, MyTheme.ThemeVersion)>
        Friend Class MyTheme
            Implements ITheme
     
    #Region "ITheme Members"
     
            Public ReadOnly Property ColorAndFontScheme As Uri Implements ITheme.ColorAndFontScheme
                Get
                    Return New Uri("/MyThemeExtension.Client;component/Presentation/Themes/MyTheme.xaml", UriKind.Relative)
                End Get
            End Property
     
            Public ReadOnly Property Id As String Implements ITheme.Id
                Get
                Return MyTheme.ThemeId
                End Get
            End Property
     
            Public ReadOnly Property Version As String Implements ITheme.Version
                Get
                Return MyTheme.ThemeVersion
                End Get
            End Property
     
    #End Region
     
    #Region "Constants"
     
            Friend Const ThemeId As String = "MyThemeExtension:MyTheme"
            Friend Const ThemeVersion As String = "1.0"
     
    #End Region
     
        End Class
     
    End Namespace

    You can then add a very basic button style with rounded corners to the bottom of your theme xaml file:

    <Style TargetType="Button" x:Key="DefaultButtonStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="ButtonBorder"
                           CornerRadius="4"
                           BorderBrush="{StaticResource ButtonBorderBrush}"
                           Background="{StaticResource ButtonBackgroundBrush}">
                        <ContentPresenter Content="{TemplateBinding Content}"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"/>
                    < /Border>
                < /ControlTemplate>
            < /Setter.Value>
        < /Setter>
    < /Style>
     
    <Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}" />


    But if you run and test your extension now, the buttons in your test application will be unaffected by your added style.  To have your style used, you must add a new class to your theme_extension.client project that implements IThemeExtension:

    Imports System.ComponentModel.Composition
    Imports Microsoft.LightSwitch.Theming
     
    Namespace Presentation.Themes
     
        <Export(GetType(IThemeExtension))>
        <ThemeExtension(MyTheme.ThemeId)>
        Friend Class MyStyle
            Implements IThemeExtension
     
            Public Function GetControlStyleResources(themeId As String, themeVersion As String, modules As IEnumerable(Of Microsoft.LightSwitch.Model.IModuleDefinition)) As IEnumerable(Of Uri) Implements IThemeExtension.GetControlStyleResources
                Return New List(Of Uri) From {New Uri("/MyThemeExtension.Client;component/Presentation/Themes/MyTheme.xaml", UriKind.Relative)}
            End Function
        End Class
     
    End Namespace

    Now when you run and test your extension you will see that the buttons have the rounded-corner style!

    If you prefer, as I do, to use ExtensionsMadeEasy so you can modify your theme from inside your Lightswitch application, change the theme class to inherit from EasyThemeWithExtensionExporter instead of EasyThemeExporter and implement IThemeExtension:

    Imports ExtensionsMadeEasy.ClientAPI.Theme
    Imports Microsoft.LightSwitch.Theming
    Imports System.ComponentModel.Composition
     
    Namespace LightSwitchApplication
     
        Public Class MyTheme
            Inherits EasyThemeWithExtensionsExporter(Of MyTheme, MyTheme)
            Implements ITheme, IThemeExtension
     
            Public ReadOnly Property ColorAndFontScheme As Uri Implements ITheme.ColorAndFontScheme
                Get
                    Return New Uri(String.Format("/{0};component/Theme/{1}", Me.GetType.Assembly.FullName.Split(",")(0), "MyTheme.xaml"), UriKind.Relative)
                End Get
            End Property
     
            Public ReadOnly Property Id As String Implements ITheme.Id
                Get
                    Return "My Theme"
                End Get
            End Property
     
            Public ReadOnly Property Version As String Implements ITheme.Version
                Get
                    Return "1.0"
                End Get
            End Property
     
            Public Function GetControlStyleResources(themeId As String, themeVersion As String, modules As IEnumerable(Of Model.IModuleDefinition)) As IEnumerable(Of Uri) Implements IThemeExtension.GetControlStyleResources
                Return New List(Of Uri) From {New Uri(String.Format("/{0};component/Theme/{1}", Me.GetType.Assembly.FullName.Split(",")(0), "MyTheme.xaml"), UriKind.Relative)}
            End Function
     
        End Class
     
    End Namespace

    Either method will allow you to use your own styles for the buttons in Lightswitch.

    Kirk
    You are not authorized to post a reply.


    Latest Microsoft Visual Studio LightSwitch Forum Threads That Have Answers

    One can use the following code in the created event of a screen to select the first item in a visual collection bound to a Table control (or any list control - code based on an old example from Huy): myapp.MyScreen.created = function (screen) { var visualCollection = screen.Orders; function selectFirst() { var first = visualCollection.data[0]; visualCollection.selectedItem = (first) ? first : null; } if (visualCollection.state === msls.VisualCollection.State.idle) { // If the visual collection is already loaded, try selecting the first item. selectFirst(); } else { // Otherwise, listen to the state change event and when the visual collection is loaded, // select the first item. Also remove the event handler because this should only happen once. function onVisualCollectionStateChanged() { if (visualCollection.state === msls.VisualCollection.State.idle) { visualCollection.removeChangeListener("state",
    Read more...

    I have a modal dialog screen that needs to be larger than the default in both height and width. I can use one of the Group control post-render methods on that dialog to set the height and Width, but I cannot seem to shift the dialog up by changing the top-margin of the dialog. I want the dialog to move up due to the fact that it is so large. This is the code in the Group control post-render method: myapp.MyLargePicker.SomeGroupControl_postRender = function (element, contentItem) { // set dialog width to 1200px $('div[class~="msls-dialog-frame"]').css('maxWidth', '1200px'); // set dialog height to 800px $('div[class~="msls-dialog-inner-frame"]').css('height', '800px'); // move the dialog up (it moves up and then down again??) setTimeout(function () { $('div[class~="msls-dialog-frame"]').css('margin-top', '10px'); }); }; Setting the margin-top above needs to be set inside the timeout() function otherwise it
    Read more...

    I have a table containing FirstName and LastName and am trying to project that as LastName, FirstName in a Table. I add a local property FullName in the client and add post render code: myapp.BrowseCustomerItems.FullName_postRender = function (element, contentItem) { function fullName() { return contentItem.data.LastName + ", " + contentItem.data.FirstName; } contentItem.dataBind("screen.ContentItems.FullName", fullName) }; The dataBind is not working.  I have tried using "screen.ContentItems.CustomerItems.FullName" as well. I hope the screen shot from VS2013 below will help.
    Read more...

    Is LightSwitch available for Visual Studio 2013 Express?  Is there an OS dependency for this and if so where is it documented?
    Read more...

    I'm having trouble in the HTML client adding new records with several relationships and could use a nudge in the right direction. I have three related tables.  'Order', 'Order Item' and 'Warehouse'.  Their relationships are: 1. The Order table has a one to many relationship to the Order Item table (example: an automobile Order needs 4 tire Order Items.) 2. The Warehouse table also has a one to many relationship with the Order Item table (example #2: A tire Order Item must come from some Warehouse.) This constitutes a many-to-many relationship between Order and Warehouse, and presents problems when adding new Orders.  (At least, I'm having problems.) For instance, let's say I'm on the Add Order screen and I want to add some Order Items at the same time.  Ordinarily that wouldn't be a problem with Lightswitch since you can 'include' the Child relationship on the Parent's Add/Edit screen and add children as you add the Parent. But in this case, when adding an
    Read more...

    1234

    Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation