我需要一些关于如何修复这个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“):
<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>谢谢你的建议!
发布于 2011-05-20 23:32:14
我不知道到底发生了什么,但只有"format c:\“帮助我解决了这个问题:(没有任何东西,包括reinstal VS和所有依赖项,都没有帮助...令人悲哀的是:
发布于 2011-05-19 03:20:48
您不应该使用边距指定控件位置,就像在winForms中使用location一样。相反,让WPF自动排列控件,如下所示:
<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>这将比硬编码所有控制位置要好得多,也更灵活。
发布于 2011-05-19 01:51:50
您是否为这些控件中的任何一个设置了指定边距设置的默认样式?它们看起来像:
<Style TargetType="{X:Type Button}>
</Style>在这一点上,我能理解的唯一一件事是,你有一个自定义的默认控件样式,它试图使用边距属性中的资源,而资源要么不是正确的类型,要么是没有正确转换。
https://stackoverflow.com/questions/6029987
复制相似问题