c# - Awesomium 在 WindowsBase.dll 中引发 ArgumentException

标签 c# wpf awesomium

我正在使用 WPF 制作一个应用程序,并且我有一个带有 Awesomium WebControl 的 UserControl。

当我将此 UserControl 的副本添加到主窗口时,我从 WindowsBase.dll 收到 ArgumentException,指出“宽度和高度必须为正数”。

这是用户控件:

<UserControl x:Class="ForumPost.ForumPost"
         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" MinWidth="505" MinHeight="250" xmlns:my="http://schemas.awesomium.com/winfx">
<Grid Name="postGrid" Margin="5">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Grid Background="#3166A1">
        <Grid.RowDefinitions>
            <RowDefinition MinHeight="150" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="150" />
            <ColumnDefinition MinWidth="100" />
            <ColumnDefinition MinWidth="125" />
            <ColumnDefinition MinWidth="125" />
        </Grid.ColumnDefinitions>

        <Grid Height="150">
            <Grid.RowDefinitions>
                <RowDefinition Height="25" />
                <RowDefinition Height="125" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="20"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <Image Margin="0 0 5 0" Name="specialUserFlag"/>

                <TextBlock TextAlignment="Center" FontWeight="Bold" FontSize="16" Foreground="White" Name="postUsername" Grid.Column="1"/>
            </Grid>

            <Image Grid.Row="1" MaxWidth="125" MaxHeight="125" Name="postAvatar" />
        </Grid>

        <TextBlock Grid.Column="2" TextAlignment="Center" FontWeight="Bold" FontSize="16" Foreground="White" VerticalAlignment="Center"  Name="postTimestamp" TextWrapping="Wrap" />

    </Grid>
    <my:WebControl Grid.Row="1" Name="webBrowser"/>
</Grid>    

这是我的主窗口,正如 @LukeWoodward 所要求的:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="Saxaphone.MainWindow"
    Title="MainWindow" Height="850" Width="1600"
    Icon="main.ico">

<Grid x:Name="MainGrid">
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="305" />
        <ColumnDefinition MinWidth="1017" />
    </Grid.ColumnDefinitions>

    <TreeView x:Name="ForumView" ScrollViewer.HorizontalScrollBarVisibility="Diforumbled" Style="{DynamicResource ForumViewStyle}" SelectedItemChanged="ForumView_SelectedItemChanged" />

    <Grid x:Name="forumGrid" Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="512" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" Grid.Column="0" Height="{Binding ActualHeight, ElementName=forumGrid}">
                <StackPanel x:Name="forumThreads"></StackPanel>
        </ScrollViewer>

        <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" Grid.Column="1" Height="{Binding ActualHeight, ElementName=forumGrid}">
            <StackPanel x:Name="forumPosts"/>
        </ScrollViewer>
    </Grid>
</Grid>

最佳答案

我现在已经能够重现您收到的 ArgumentException 了。我怀疑这是 Awesomium 中的一个错误。我建议您联系 Awesomium 支持:http://support.awesomium.com/ .

我发现以下 XAML 足以重现 ArgumentException。不需要任何用户控件,也不需要在运行时添加控件:

<StackPanel>
    <as:WebControl xmlns:as="http://schemas.awesomium.com/winfx" />
</StackPanel>

我发现可以通过设置显式 Width 来解决此问题。和Height关于WebControl 。似乎是WebControl不喜欢呆在 StackPanel 里面除非它( WebControl )两者 WidthHeight设置。

关于c# - Awesomium 在 WindowsBase.dll 中引发 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8959975/

相关文章:

javascript - 执行 javascript 'undefined' 输出但它按预期工作

c# - 跨两个列表应用运算符的 C# 惯用方法是什么?

c# - 将字典中的值分配给动态对象 C#

c# - 使用 : The magic number in GZip header is not correct. 解压缩上传的文件确保您传入的是 GZip 流

c# - 如何反序列化 JSON 数组并将生成的对象绑定(bind)到 WPF DataGrids?

c# - 在我想要等待的方法上获得 Cannot await void

c# - WPF 的 CPU throttle 问题

c# - 使用正则表达式 C# 解析 URL

c# - Awesomium C# WebControl,更改代理设置

c# - 在 DocumentReady 事件中文档没有准备好?