Select to view content in your preferred language

Using Expression Blend 4 binding List Box item source to Check box

1356
8
12-28-2010 04:47 AM
MuhammadWaqar_ul_islam
Occasional Contributor
I am using expression blend 4 using the Arcgis API for Microsoft Silverlight/WPF
i have bind the list box from map.layer
but enable to bind the check box with list box properties which is bind with Map
through XAML code it is done
but i want to know is that possible in Expression blend
please describe the method to bind check box that occurs in List box with map properties
0 Kudos
8 Replies
DanielWalton
Frequent Contributor
It's difficult to tell exactly what you are trying to do. Could you perhaps post some of your code? In general I have found it tough to setup complex bindings using Blend. 🙂
0 Kudos
AliMirzabeigi
Emerging Contributor
You can find a blog here about how to use Blend to customize look and feel of the ArcGIS Silverlight API controls.
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
<ListBox Margin="0,5,0,0" ItemsSource="{Binding ElementName=MyMap, Path=Layers.[DynamicLayerCalifornia].Layers}"
                         Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <CheckBox Margin="2"
                                  Name="DynamicLayerCalifornia"
                                  Content="{Binding Name}"
                                  IsChecked="{Binding DefaultVisibility}"
                                  Tag="{Binding ID}"
                                  ClickMode="Press"
                                  Click="CheckBox_Click" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

this  code works XAML (perfectly)
but how can i bind list box with checkbox  in Expression Blend 4 without using the code
0 Kudos
AliMirzabeigi
Emerging Contributor
- To set the ItemsSource property of your ListBox control follow the instructions below:
1. Select your ListBox in Expression Blend and look for "ItemsSource" property in "Common Properties" section of the Properties tab.
2. Use "Advanced Options" indicator --> Data Binding...
3. In "Create Data Binding" window click on "Element Property" tab, select your map control in "Scene elements" list.
4. Check "Use a custom path expression" CheckBox and type in "Layers.[DynamicLayerCalifornia].Layers" for its TextBox (Note that you could have simply selected the "Layers" property in "Properties" list on the right side of this tab however; you are specifically looking for layers collection in your dynamic layer hence; need to type it in).
5. Click "OK", you are done with the element data binding of your ListBox.

- To customize your ListBox ItemTemplate do the following:
1. In Expression Blend right click on your ListBox --> Edit Additional Templates --> Edit Generated Items (ItemTemplate) --> Create Empty.
2. In "Create DataTemplate Resource" window enter the name/key for the template you are creating for your ListBox.
3. Drag and drop a CheckBox control inside of the "Grid" in the data template you are editing (you should see a small transparent squared Grid).
4. Set the properties of the CheckBox after selecting it, i.e. ClickMode, Margin, etc... For "IsChecked" property of the CheckBox use the "Advanced Options" indicator --> Data Binding... and in "Create Data Binding" window check "Use a custom path expression" CheckBoxand type in "DefaultVisibility" after clicking on the "Data Context" tab. Do the same for the "Content" and "Tag" properties.
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
Thanks for Helping ali
code generated by XAML after doing all step u mention but same problem occurs no binding
      list box apperas but no check box appears



          <Grid x:Name="My_New_Grid" HorizontalAlignment="Right" Height="264" Margin="0,16,8,0" VerticalAlignment="Top" Width="136">
         <ListBox x:Name="listBox" ItemsSource="{Binding Layers.[Karachi].Layers, ElementName=listBox}">
          <ListBox.Resources>
           <DataTemplate x:Key="My_List_Data_Temp">
            <Grid x:Name="grid" >
             <CheckBox x:Name="checkBox" Content="{Binding Name, ElementName=checkBox}" Margin="0,0,0,3" d:LayoutOverrides="Width, Height" IsChecked="{Binding DefaultVisibility, ElementName=checkBox, Mode=TwoWay}" Tag="{Binding ID, ElementName=checkBox}" IsHitTestVisible="False" />
            </Grid>
           </DataTemplate>
          </ListBox.Resources>
          <ListBox.ItemTemplate>
           <StaticResource ResourceKey="My_List_Data_Temp"/>
          </ListBox.ItemTemplate>
         </ListBox>
        </Grid>
0 Kudos
DanielWalton
Frequent Contributor

          <ListBox x:Name="listBox" ItemsSource="{Binding Layers.[Karachi].Layers, ElementName=listBox}">
                .
.
.
<CheckBox x:Name="checkBox" Content="{Binding Name, ElementName=checkBox}" IsChecked="{Binding DefaultVisibility, ElementName=checkBox, Mode=TwoWay}" Tag="{Binding ID, ElementName=checkBox}"  />
                       


For starters, remove the ElementName from your bindings. ElementName tells Silverlight to look for another XAML control by name to specify the source of the binding. In your case the source of all the checkbox bindings will be understood by Silverlight to be the individual (sub)layers, since the control is in the ItemTemplate.

Also, it looks like you're trying to create a listbox with checkboxes to show and hide the sublayers. Binding the checkbox to layer.DefaultVisibility will set the layer visibilty on startup, but it won't toggle the layer visibility at runtime.  Several users on this forum have done this in other ways, Here is an example. You might also look at this interactive sample for a pattern.

Hope this helps you!
0 Kudos
MuhammadWaqar_ul_islam
Occasional Contributor
Dear Daniel
thanks for replying i am new user of XAML & SILVERLIGHT
I want to do this in blend 4 using drag and drop not through code is there any possibility
or is there any video tutorial for arcgis silver light api used in Expression Blend 4 for sub layer sample
0 Kudos