質問

I am developing silverlight application. I am using itemscontrols in silverlight to diaply the UI according to requirement.

<ItemsControl x:Name="CertificationsAndLicensesItemsControl">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>                               
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>

                        <Grid Grid.Row="0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid Grid.Row="0" Grid.Column="0" Width="500">
                                <TextBlock TextWrapping="Wrap" Foreground="Green" Text="{Binding Path=CertificationsAndLicensesTitle}" FontWeight="Bold" Margin="5"></TextBlock>
                            </Grid>
                            <Grid Grid.Row="0" Grid.Column="1">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock FontWeight="Bold" Text="Valid from:" HorizontalAlignment="Left" Margin="5"></TextBlock>
                                    <TextBlock Text="{Binding Path=ValidFrom}" Margin="5" ></TextBlock>
                                    <TextBlock Text="Until" Margin="5"></TextBlock>
                                    <TextBlock Text="{Binding Until}" Margin="5"></TextBlock>
                                </StackPanel>
                            </Grid>
                            <Grid Grid.Row="1" Grid.ColumnSpan="2">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
                                    <Button x:Name="EditButton" Tag="{Binding Path=ID}" Content="Edit" Click="EditButton_Click"></Button>
                                    <Button x:Name="DeleteButton" Tag="{Binding Path=ID}" Content="Delete" Click="DeleteButton_Click"></Button>
                                </StackPanel>
                            </Grid>
                        </Grid>

                    </Grid>

                </DataTemplate>

            </ItemsControl.ItemTemplate>
        </ItemsControl>

The code behind is as follows

private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            //int a = 10;
            //CertificationsAndLicensesChildWindow obj = new CertificationsAndLicensesChildWindow();
            //obj.Show();
            ChildWindow1 obj1 = new ChildWindow1();
            obj1.Show();
        }

        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            CertificationsAndLicensesChildWindow obj = new CertificationsAndLicensesChildWindow();
            obj.Show();
        }

The child window doesnt get displayed on button click. The whole UI gets disappear after I click the button. If I remove the following sentences

ChildWindow1 obj1 = new ChildWindow1();
                obj1.Show();

Then at least breakpoint gets hit. If I keep the above sentenses as it is then breakpoint does not get hit. How shuld I display the child window on button click ? Can you please provide me any code or link through which I can resolve the above issue

役に立ちましたか?

解決

Disappearing UI almost always means unhandled exception - propably there is some error during ChildWindow1 creation/display. You can try to attach handler for unhandled exception in App class, if it's not attached (do it in App constructor), and set a breakpoint in unhandled exception handler. This should help You track what exception is causing UI dissapearance.

By default, when creating Silverlight project, there is hander in place and it reports exceptions to DOM - You should be able to see exception in JavaScript console.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top