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

将这个UserControl的副本添加到主窗口的那一刻,我从WindowsBase.dll获得ArgumentException,说“宽度和高度必须为正”。

这是UserControl:

<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中的错误。我建议您通过http://support.awesomium.com/与Awesomium支持人员联系。

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

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


我发现可以通过在Width上设置显式的HeightWebControl来解决此问题。除非WebControlStackPanel都设置了,否则WebControl似乎不喜欢位于Width内部。

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

10-12 22:14