RAMe0
RAMe0

Reputation: 1267

Set property '...Margin' threw an exception?

I need some advice on how to fix this bug:

Exception:

"'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'."

I dont know how it could happen, because I didn't touch XAML yet. I used only designer.

Here is my XAML (There is no any "Auto" in properties ):

<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>

Thanks for any advice!

Upvotes: 1

Views: 2968

Answers (3)

RAMe0
RAMe0

Reputation: 1267

I don't know really what happened, but only "format c:\" helped me solve this problem :( Nothing, including reinstal VS and all dependencies, didn't help... And that's sad :(

Upvotes: -1

Cobold
Cobold

Reputation: 2613

You shouldn't specify control location with Margin, like you would do it with location in winForms. Instead let WPF arrange the controls automatically, like this:

        <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>

It would be much nicer and flexible than hard coding all control locations.

Upvotes: 2

CodeWarrior
CodeWarrior

Reputation: 7468

Do you have any default styles setup for any of those controls that specifies a margin setting? They would look like:

<Style TargetType="{X:Type Button}>

</Style>

At this point the only thing I can figure is going on is that you have a custom default control style that is trying to use a resource in the margin property and the resource either is not the right type or it is not converting properly.

Upvotes: 0

Related Questions