locked
Conditional Styles in Lightswitch RRS feed

  • Question

  • Ok let’s make it simple I have two pieces of data in my entity and I want to format one on screen using the info in the other.

    Picture and Color

    The color indicates a organization of the thing pictured. It in no way directly reflects the picture which is a general picture of a model. but to keep identical models separated they each have a color indicator placed on them in real life. I want to use the style tag in the Client.LSML to define a Border around the picture and the ColorOFBorder=Color.

    The target code for the screen Property "picture" on the client side is...

                        <ContentItem

                          DataType="Microsoft.LightSwitch.Extensions:Image?"

                          Kind="Value"

                          Name="Picture"

                          Placement="Image">

                          <ContentItem.DataSource>

                            <ScreenExpressionTree>

                              <ChainExpression>

                                <MemberExpression

                                  Member="LightSwitchCommonModule:Miniature/Properties[Picture]" />

                              </ChainExpression>

                            </ScreenExpressionTree>

                          </ContentItem.DataSource>

                          <ContentItem.PropertySources>

                            <ControlPropertySource

                              Property="Microsoft.LightSwitch:RootControl/Properties[HorizontalAlignment]">

                              <ScreenExpressionTree>

                                <ConstantExpression

                                  ResultType=":String"

                                  Value="Center" />

                              </ScreenExpressionTree>

                            </ControlPropertySource>

                            <ControlPropertySource

                              Property="Microsoft.LightSwitch:RootControl/Properties[AttachedLabelPosition]">

                              <ScreenExpressionTree>

                                <ConstantExpression

                                  ResultType=":String"

                                  Value="Top" />

                              </ScreenExpressionTree>

                            </ControlPropertySource>

                          </ContentItem.PropertySources>

                        </ContentItem>

    The target code for the screen property "color" on the client side is...

                        <ContentItem

                          DataType=":String?"

                          Kind="Value"

                          Name="PlayerCharacters_SelectedItem_BaseColor">

                          <ContentItem.DataSource>

                            <ScreenExpressionTree>

                              <ChainExpression>

                                <MemberExpression

                                  Member="CampaignDetails/Properties[PlayerCharacters]" />

                                <MemberExpression

                                  Member="SelectedItem" />

                                <MemberExpression

                                  Member="BaseColor" />

                              </ChainExpression>

                            </ScreenExpressionTree>

                          </ContentItem.DataSource>

                        </ContentItem>

                      </ContentItem>

    The sample code for adding style is this were a DataGrid and I just changes the background color of the "Color" Property in the screen after it is listed.

        <DataGrid Name="dataGrid1" Margin="12,12,0,0">
           
    <DataGrid.RowStyle>
               
    <Style TargetType="DataGridRow">
                   
    <Setter Property="Background" Value="{Binding Path=colorCol}" />
               
    </Style>
           
    </DataGrid.RowStyle>
       
    </DataGrid>

    Monday, September 30, 2013 8:08 PM

All replies

  • Hi Guys,

    Welcome to MSDN forums.

    Since the issue is related to Lightswitch Forums, I moved it to Lightswitch Forums where you can contact EF experts. Thanks for your understanding.

    #Visual Studio LightSwitch Forums
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=lightswitch

    Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 1, 2013 6:40 AM
  • I know this is were the folks for EF "entity framework" are but I am mostly wondering how to code conditionals in Silverlight which I believe this to be coded in. I was thinking there would also be standards for defining "base color" and/or "borders" like there is in HTML and CSS in Silverlight and am mostly needing direction on what those standards are and how to apply them using one field to control the formatting of another field in the same table. In fact each field will correspond to the same entry which I believe makes this even more simple.
    Saturday, October 5, 2013 7:53 PM
  • This sample does conditional coding for a Silverlight rich client:

    Control colours and more in LightSwitch

    It is a different approach as it is targeting the Silverlight XAML/Visual tree at run-time.

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Sunday, October 6, 2013 10:34 AM
  • I haven't been able to view your downloadable sample as it was built on Visual Studio 2010 and earlier versions of Lightswitch there were many errors with the code after the conversion to Visual Studio 2012. 15 Warnings and 7 Errors Total. Below are some examples.

    Error 1 The DataType property of the ContentItem 'Value' in the Screen 'EditableBalancesGrid' cannot be resolved:  Could not resolve Id 'Microsoft.LightSwitch.Extensions:Money' to any item.  No matched model item can be found. C:\Users\Jordan Walker\Documents\Visual Studio 2012\Projects\C# DataGridColor\DataGridColor\Client\Properties\Client.lsml 2 2 

    Error 2 The DataType property of the ContentItem 'Value' in the Screen 'SearchBalances' cannot be resolved:  Could not resolve Id 'Microsoft.LightSwitch.Extensions:Money' to any item.  No matched model item can be found. C:\Users\Jordan Walker\Documents\Visual Studio 2012\Projects\C# DataGridColor\DataGridColor\Client\Properties\Client.lsml 2 2 

    Error 3 The Shell property of the Application 'LightSwitchApplication' cannot be resolved:  Could not resolve Id 'Microsoft.LightSwitch.Cosmopolitan:CosmopolitanShell' to any item.  No matched model item can be found. C:\Users\Jordan Walker\Documents\Visual Studio 2012\Projects\C# DataGridColor\DataGridColor\Client\Properties\Client.lsml 2 2 

    Error 4 The Theme property of the Application 'LightSwitchApplication' cannot be resolved:  Could not resolve Id 'Microsoft.LightSwitch.Cosmopolitan:CosmopolitanTheme' to any item.  No matched model item can be found. C:\Users\Jordan Walker\Documents\Visual Studio 2012\Projects\C# DataGridColor\DataGridColor\Client\Properties\Client.lsml 2 2 

    Warning 5 The element 'PropertyGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element 'UseDesignTimeFeatures' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. List of possible elements expected: 'Property, AllowUnsafeBlocks, AppConfigForCompiler, ApplicationIcon, ApplicationRevision, ApplicationVersion, AppDesignerFolder, AspNetConfiguration, AssemblyKeyContainerName, AssemblyKeyProviderName, AssemblyName, AssemblyOriginatorKeyFile, AssemblyOriginatorKeyFileType, AssemblyOriginatorKeyMode, AssemblyType, AutorunEnabled, BaseAddress, BootstrapperComponentsLocation, BootstrapperComponentsUrl, BootstrapperEnabled, CharacterSet, CheckForOverflowUnderflow, CLRSupport, UseDebugLibraries, CodePage, Configuration, ConfigurationName, ConfigurationOverrideFile, CreateDesktopShortcut, CreateWebPageOnPublish, CurrentSolutionConfigurationContents, DebugSecurityZoneURL, DebugSymbols, DebugType, DefaultClientScript, DefaultHTMLPageLayout, DefaultTargetSchema, DefineConstants, DefineDebug, DefineTrace, DelaySign, DisableLangXtns, DisallowUrlActivation, CodeAnalysisAdditionalOptions, CodeAnalysisApplyLogFileXsl, CodeAnalysisConsoleXsl, CodeAnalysisCulture, CodeAnalysisFailOnMissingRules, CodeAnalysisForceOutput, Co.... C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v2.0\Microsoft.LightSwitch.targets 19 10 Miscellaneous Files

    Warning 6 The element 'ItemGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element '_BuildFile' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. List of possible elements expected: 'Item, Reference, COMReference, COMFileReference, Xdcmake, Bscmake, ClCompile, ClInclude, Midl, ResourceCompile, PreLinkEvent, CustomBuildStep, Manifest, ProjectConfiguration, ProjectCapability, NativeReference, ProjectReference, Compile, EmbeddedResource, Content, Page, Resource, ApplicationDefinition, None, BaseApplicationManifest, Folder, Import, Service, WebReferences, WebReferenceUrl, FileAssociation, BootstrapperFile, PublishFile, PRIResource, AppxSystemBinary, AppxReservedFileName, AppxManifestFileNameQuery, AppxManifest, StoreAssociationFile, CodeAnalysisDependentAssemblyPaths, CodeAnalysisDictionary, CodeAnalysisImport, Link, ResourceCompile, PreBuildEvent, PostBuildEvent' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v2.0\Microsoft.LightSwitch.targets 34 10 Miscellaneous Files

    • Edited by reigh7 Monday, October 7, 2013 8:44 PM
    Monday, October 7, 2013 8:43 PM
  • VS2010? No idea why you came to that conclusion. The download even contains a file 'DataGridColor.v11.suo', and as the sample documentation states it was built using VS2012 RTM.

    It has been download by a few thousand people without these errors: in your environment it cannot find the Cosmopolitan theme or shell?

    The code should be easy to transfer across to a project. It still builds and runs here on VS2012 Update 3.

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Monday, October 7, 2013 10:27 PM
  • Maybe it has to do with the C# version and the VB version I uploaded the C# version and it had to be converted from a previous edition of Visual Studio to run the project. This is common among all of my projects written in visual studio before 2012 and Lightswitch V3. Converted projects do not have access to the cosmopolitan theme as my older projects do not but all new projects do have access to it.
    Tuesday, October 8, 2013 1:57 AM
  • It has nothing to do with that, I just re-downloaded the sample and it works fine, but ingrained in me is to do the correct steps.

    I hope you laugh rather than cry -> you forgot to 'unblock' the zipped sample before extracting it :)

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Tuesday, October 8, 2013 7:46 AM
  • I figured it out I was not blocked when unzipped it. I laughed when I realized adding the extension for Cosmopolitan manually along with other extensions fixed it. It occurred to me that older files that are opened up and converted by Visual Studioi2012 have to have there extensions disable first then re-enabled later.

    PS is there any written documentation on how the project code was created or modified. I may want to do the same for a blue theme/shell project of mine. I prefer the interface over cosmopolitan.

    Tuesday, October 8, 2013 4:16 PM
  • The code (mostly bindings) is in the client app not the theme or shell.

    I would suggest walking through all the screens in the sample and using them and see the effects. The sample code topics then are datagrid grouping, sorting, alternate row color, cell bindings and row bindings. Each screen implement one or more of these topics. There is not really much code.

    There is a bonus screen with styles for textboxes, labels, background etc..

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Wednesday, October 9, 2013 10:59 AM
  • The code (mostly bindings) is in the client app not the theme or shell.

    ...The sample code topics then are datagrid grouping, sorting, alternate row color, cell bindings and row bindings. Each screen implement one or more of these topics. There is not really much code.

    Yes but were do I edit the data bindings from in your project. I see they are bound but how?

    Second were do I find the information on the topics you list in the second paragraph?

    Friday, October 18, 2013 2:34 AM
  • There is a wealth of information regarding these topics on the internet and MSDN. They are all Silverlight, Xaml and DataGrid topics:

    For example: c# corner

    There is little specific to LightSwitch apart from the use of 'FindControl' and waiting for control event loading. At most each involves half a dozen lines of code or less.

    You just have to remember it is Silverlight.


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Friday, October 18, 2013 12:37 PM
  • It may all be Silverlight but it would help to know how to access the parts of the code you edited from a lightswitch project. like did you go to a the Accounts table select the color field and click "write code" "Color_Changed" or did you open the projects file view and go to the client "User code" and how did you create those instances of user code in a lightswitch project.
    Friday, October 18, 2013 7:42 PM