English 中文(简体)
WPF 元素主机每第二次崩溃一次
原标题:WPF element host is crashing every second time

我有一个 WPF 用户控制器在窗口窗体项目里, 我遇到了一个问题。 每次我作为元素主机的应用程序崩溃一次, 都会在用户控制中输入数据 。

当我把这个放进WPF项目时,同样的事情也会发生。 每隔一次我的应用程序正常启动一次。

知道有什么问题吗?这是我的用户控制代码:

<UserControl x:Class="Fleet_management.Info"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" Height="492" Width="578">
    <UserControl.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFE2E2E2" Offset="0" />
            <GradientStop Color="White" Offset="1" />
        </LinearGradientBrush>
    </UserControl.Background>

    <UserControl.Resources>
        <XmlDataProvider x:Key="rssData" XPath="//item" Source="******" />
    </UserControl.Resources>

    <Grid Margin="3" Height="598" Width="565">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="252*" />
            <ColumnDefinition Width="90*" />
            <ColumnDefinition Width="223*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="177*" />
            <RowDefinition Height="55*" />
            <RowDefinition Height="122*" />
            <RowDefinition Height="177*" />
        </Grid.RowDefinitions>

        <ListBox x:Name="lstItems" Margin="3,0" ItemsSource="{Binding Source={StaticResource rssData}}"
                 SelectedIndex="0" VerticalAlignment="Stretch" FontStretch="Normal" FontSize="14" FontFamily="Lucida Sans Unicode" Grid.ColumnSpan="3">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Width="20" Margin="3" Source="{Binding XPath=enclosure/@url}" />
                        <TextBlock Margin="3" VerticalAlignment="Center" Text="{Binding XPath=title}" FontWeight="Bold" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <StackPanel Grid.Row="1" Orientation="Vertical" DataContext="{Binding ElementName=lstItems, Path=SelectedItem}" Margin="0,0,0,5" Grid.ColumnSpan="3">
            <TextBlock Margin="3" FontSize="13" FontWeight="Bold" Text="{Binding XPath=title, Path=InnerText}" />
            <TextBlock Margin="3" Opacity="0.72" Text="{Binding XPath=pubDate}" />
        </StackPanel>
        <ScrollViewer CanContentScroll="True" Grid.Row="2" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"  DataContext="{Binding ElementName=lstItems, Path=SelectedItem}" Margin="0,0,3,115" Grid.RowSpan="2" Grid.ColumnSpan="3">
            <TextBlock  Margin="3"
                       FontStyle="Italic" Text="{Binding XPath=description, Path=InnerText}" TextWrapping="Wrap" TextAlignment="Justify" AllowDrop="False"
                       Foreground="#FF0000E7" FontFamily="Lucida Sans Unicode" FontSize="14" Padding="0,0,5,0" VerticalAlignment="Center" />
        </ScrollViewer>

    </Grid>
</UserControl>
最佳回答

您可能想要检查包含数据的 xml 文档是否仍然被上一个应用程序锁定 。

关闭此应用程序 。 检查 xml 文件是否仍在使用中 。

另外, 添加例外处理, 以便您知道正在扔出什么例外 。 使用至少 < a href=" http:// msdn. microsoft. com/ en- us/library/ system. windows. application. dispatcherunhandled Exception. aspx" rel = “ nofollow” > application. Dispather Un handedexeption

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签