Working with Lightswitch, Silverlight & custom controls
Asked Answered
C

1

6

I have a screen with some data. Inside the screen I have two custom controls (on the left and right side).

What I need to do is the following:

Bind some data from a database to some Controls in the first Custom control. (fill a list, combobox etc, not so much the problem)

The user then can select an entry in the list, press a button -> the second CustomControl should now be made visible; request some data from the DB, based on the selection and dynamicly create and show a Chart.

So I know how to build the chart and build the Controls. But how can I access the Data from the screen through code and access another CustomControl from within the first CustomControl?

Edit:

Things I found out.

  1. Access control from screen

    this.FindControl("yourControl");

  2. Do something with the control:

    this.FindControl("yourControl").ControlAvailable += ( (o,e) => { YourControlType myControl = e.Control as YourControlType; });

  3. Access screen data

        IContentItem dataContext = this.DataContext as IContentItem;
        IScreenObject screen = dataContext.Screen;
    
        IScreenProperty prop = screen.Details.Properties["yourProperty"];
    
        VisualCollection<yourProperty> items = prop.Value as  VisualCollection<yourProperty>;
    
  4. Show new screen

    Application.Current.Details.Dispatcher.BeginInvoke(() => Application.Current.ShowGraphScreen(reportItem.BlockID));

Maybe this will help someone.

Carping answered 13/8, 2012 at 15:0 Comment(2)
Does this link help? Custom Control BindingIngram
+1 just for the little gems on how to access screen data. As custom controls now have to be in a separate library adding a reference to the generated Application.common of the client app, combined with your examples, was a great help.Hogtie
M
0

Create a Filter query with a Parameter on the collection in the DB that you want the data from. Add this query to the screen and set the Parameter Binding to FirstCustomControl.

Drag the query onto the screen tree, change it to a chart, and check the binding as per Yann's link.

You would then need code similar to the following to show/hide the control:

partial void ScreenName_InitializeDataWorkspace(List<IDataService> saveChangesTo)
{
    this.FindControl("SecondCustomControl").IsVisible = False;
}

partial void ButtonName_Execute()
{
    this.FindControl("SecondCustomControl").IsVisible = True;
}

Since SecondCustomControl (I'm assuming this is the chart) is bound to the query and the query's parameter is bound to the value selected in the FirstCustomControl, the data gathering is all done in the background.

Marinara answered 14/8, 2012 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.