2014-04-02 18 views
5

Đối với một dự án tôi đang sử dụng XAML. Tôi đã lệch màn hình của mình ở các phần khác nhau. Khoảnh khắc khi tôi thêm nút, tôi gặp lỗi.XAML Các yếu tố bất động sản

Lỗi:

'property elements cannot be in the middle of an element's content'

Mã Tôi đang sử dụng cho nút nơi lỗi đã được tìm thấy:

<Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

Có ai biết vấn đề là gì và làm thế nào tôi có để giải quyết nó ?

Phần còn lại của các mã:

<Window x:Class="Pesten.View.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <Image Grid.RowSpan="4" Grid.ColumnSpan="3" Stretch="Fill" Source="pestenbg.jpg" VerticalAlignment="Top" HorizontalAlignment="Center"/> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="4*"/> 
     <ColumnDefinition Width="2*"/> 
     <ColumnDefinition Width="4*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="5*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="2*"/> 
    </Grid.RowDefinitions> 

    <Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

</Grid> 

</Window> 
+4

Bạn có thể hiển thị phần còn lại của tệp XAML không? – BenjaminPaul

+0

Phần tử Nút chính nó có vẻ ổn. Bạn có thể đăng thêm XAML không? Có lẽ toàn bộ nó? –

+0

có thể trùng lặp với [Lỗi WPF: Các phần tử thuộc tính không thể ở giữa nội dung của phần tử. Họ phải ở trước hoặc sau nội dung] (http://stackoverflow.com/questions/26524787/wpf-error-property-elements-cannot-be-in-the-middle-of-an-elements-content-th) – Dzyann

Trả lời

6

Bạn đã xác định một hình ảnh trong lưới trước khi tính lưới. Di chuyển điều này đến sau các định nghĩa hàng và cột.

+1

Cảm ơn! Sai lầm ngớ ngẩn ... – Klyner

+0

Rất vui được giúp đỡ. Đánh dấu để chấp nhận câu trả lời và sau đó tất cả chúng ta đều hạnh phúc :-) –

+0

Tôi sẽ phải chờ đợi sự chậm trễ 5 phút. – Klyner

0

Đặt định nghĩa cột và hàng trực tiếp sau thẻ mở. Tất cả nội dung phải tuân theo (tức là và).

1

Bạn đang thêm Button kiểm soát tại địa điểm sai của phụ huynh kiểm soát:

Property elements cannot be in the middle of an element's content

Property elements cannot be in the middle of an element's content. They must be before or after the content. This error is occurs when you attempt to use property-element syntax within an element's content.

Move Image sau ColumnDefinitions và trước Button

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="4*"/> 
     <ColumnDefinition Width="2*"/> 
     <ColumnDefinition Width="4*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="2*"/> 
     <RowDefinition Height="5*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="2*"/> 
    </Grid.RowDefinitions> 

    <Image Grid.RowSpan="4" Grid.ColumnSpan="3" Stretch="Fill" Source="pestenbg.jpg" VerticalAlignment="Top" HorizontalAlignment="Center"/> 
    <Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" /> 

</Grid> 

hoặc di chuyển cả ImageButton ở trên định nghĩa cột/hàng nhưng yo bạn không thể tách nó

Các vấn đề liên quan