How to bind a query returns/results to a textblock in XAML? See below. Thanks
<TextBlock x:Name="textLabel" Forground="White" Text="Total records/features found: " />
<TextBlock x:Name="featuresFound" Foreground="Red" Text="{Binding ... }" />
Hi Yurong,We take an Model-View-ViewModel (MVVM) approach with this type of binding, and I've included some code below that should help get you started. This code is from the QueryRelatedRecords tool we will be releasing shortly. Note that you do not need to use a ListBox, but it shows the pattern for binding. RelationshipSelectionView.xaml: <ListBox HorizontalAlignment="Stretch" x:Name="RelationshipsListBox" Background="Transparent" BorderBrush="Transparent" Margin="5,2,-5,0" ItemsSource="{Binding RelationshipList}"
VerticalAlignment="Stretch" DisplayMemberPath="Name" Width="300" FontFamily="SegoeUI" Grid.Row="2" Grid.ColumnSpan="3">
</ListBox>
QueryRelatedTool.cs (the tool clicked):
relationshipList = new List<Relationship>();
QueryRelatedViewModel vm = new QueryRelatedViewModel(relationshipList, MapApplication.Current.Map);
RelationshipSelectionView relationshipView = new RelationshipSelectionView();
relationshipView.DataContext = vm;
int relCount = relatesLayer.LayerInfo.Relationships.Count();
if (relCount > 1) // Layer has more than one relationship
{
foreach (Relationship rel in relatesLayer.LayerInfo.Relationships)
{
relationshipList.Add(rel);
}
}
QueryRelatedViewModel.cs:
public QueryRelatedViewModel(List<Relationship> relationships, Map Map)
{
RelationshipList = relationships;
map = Map;
}
private List<Relationship> relationshipList;
/// <summary>
/// Gets or sets the list of Relationships associated with a layer
/// </summary>
public List<Relationship> RelationshipList
{
get { return relationshipList; }
private set
{
if (relationshipList != value)
relationshipList = value;
}
}
Hope that helps,Katy
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™