Search code examples
silverlighteventsxamlbindingraise

How do I Raise an Event when the Binding is completed?


I have a TextBox in my application that i am developing and the binding is done in the xaml

I want to be able to raise an event when the binding of the TextBox Text Property is completed meaning when the text is loaded/changed through binding into the TextBox how do i achive this?

I tried TextChanged Event also Loaded Event but no luck right after the Binding is complected so how do i do it?

<ListBox x:Name="listBoxCategories" Background="Transparent" BorderThickness="0" Grid.Row="4" Grid.ColumnSpan="2" Margin="0" Padding="0" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{Binding ElementName=discussion_categoryDomainDataSource, Path=Data}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel x:Name="stackPanelCategory" Orientation="Vertical" Margin="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <TextBlock x:Name="TextBlockCategoryId" Text="{Binding Path=CategoryID}" />
                        <toolkit:Expander IsExpanded="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Style="{StaticResource ForumExpanderStyleRight}">
                            <toolkit:Expander.Header>
                                <TextBlock FontSize="16" FontWeight="Bold" Foreground="White" Margin="4,0,4,0" Text="{Binding CategoryName}" LayoutUpdated="TextBlock_LayoutUpdated" />
                            </toolkit:Expander.Header>
                            <ListBox x:Name="listBoxBoards" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Transparent" BorderThickness="0" Margin="0" Padding="0" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{Binding CategoryBoards}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Margin="0" HorizontalAlignment="Stretch" x:Name="GridBoard">
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </toolkit:Expander>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

at this line

<TextBlock x:Name="TextBlockCategoryId" Text="{Binding Path=CategoryID}" />

I want an event where when the Binding is completed i want to give a different data source for the list box under the parent stack panel so i need the binding event so when i have the catedory id int he text block which later will be hidden in the xaml ( which now is not collapsed for testing reasons )


Solution

  • This solved the problem for me :)

    <TextBlock FontSize="16" FontWeight="Bold" Foreground="White" Margin="4,0,4,0" Text="{Binding CategoryName}" Loaded="TextBlock_Loaded" />
    

    Loaded event in the inner Text block rather than the upper textblock because by the time this is loaded the upper text block's text is already bound so i can retrive the ID :)