首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否设置属性'...Margin‘引发异常?

是否设置属性'...Margin‘引发异常?
EN

Stack Overflow用户
提问于 2011-05-17 19:16:32
回答 3查看 2.7K关注 0票数 0

我需要一些关于如何修复这个bug的建议:

例外:

"'Set property 'System.Windows.FrameworkElement.Margin' threw an exception.' Line number '6' and line position '31'."

InnerException:

"'12,10,599,Auto' is not a valid value for property 'Margin'."

我不知道这是怎么发生的,因为我还没有接触XAML。我只使用了设计器。

下面是我的XAML (属性中没有任何"Auto“):

代码语言:javascript
复制
<Window x:Class="LinksGraph.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="774" Width="671" Closing="Window_Closing">
        <Grid>
            <Label Content="URL:" Height="28" Margin="12,10,599,0" Name="lURL" VerticalAlignment="Top" FontWeight="Bold" />
            <Button Content="Start" Height="23" Margin="0,44,93,0" Name="btnStart" VerticalAlignment="Top" HorizontalAlignment="Right" Width="75" Click="btnStart_Click" />
            <ProgressBar Height="10" HorizontalAlignment="Left" Margin="12,0,0,46" Name="pbStatus" VerticalAlignment="Bottom" Width="625" />
            <TextBox Height="23" Margin="56,10,107,0" Name="tbURL" VerticalAlignment="Top" />
        </Grid>
    </Window>

谢谢你的建议!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-20 23:32:14

我不知道到底发生了什么,但只有"format c:\“帮助我解决了这个问题:(没有任何东西,包括reinstal VS和所有依赖项,都没有帮助...令人悲哀的是:

票数 -1
EN

Stack Overflow用户

发布于 2011-05-19 03:20:48

您不应该使用边距指定控件位置,就像在winForms中使用location一样。相反,让WPF自动排列控件,如下所示:

代码语言:javascript
复制
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Name="lURL" FontWeight="Bold" VerticalAlignment="Center">URL:</TextBlock>
            <TextBox Name="tbURL" Grid.Column="1" VerticalAlignment="Center" Margin="4"/>
            <Button Name="btnStart" Grid.Column="2" Margin="4" Content="Start" Padding="7,2,7,2"/>
            <ProgressBar Grid.Row="2" Height="15" Name="pbStatus" Grid.ColumnSpan="3" Margin="8"/>
        </Grid>

这将比硬编码所有控制位置要好得多,也更灵活。

票数 2
EN

Stack Overflow用户

发布于 2011-05-19 01:51:50

您是否为这些控件中的任何一个设置了指定边距设置的默认样式?它们看起来像:

代码语言:javascript
复制
<Style TargetType="{X:Type Button}>

</Style>

在这一点上,我能理解的唯一一件事是,你有一个自定义的默认控件样式,它试图使用边距属性中的资源,而资源要么不是正确的类型,要么是没有正确转换。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6029987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档