Xaml Grid Wows Text Box没有出现

时间:2014-09-29 12:54:43

标签: c# xaml

我正在尝试使用网格系统作为另一个用户对我的另一个问题的建议我试图实现网格系统但是没有成功,它将按钮和网格放在我想要的位置,但文本框用于名称和with应位于listview的底部

enter image description here

这三个控件应出现在列表视图的底部

<TextBox   Name="txtDsiplayName" Text="{Binding Path=CustomColumnsDisplayName, Mode=TwoWay}"   Height="23"   
Width="452" Margin="0,149.86,0,188.5"    Grid.ColumnSpan="2"  />
<Label Content="Width:" Height="400" VerticalAlignment="Bottom" Grid.ColumnSpan="2" HorizontalAlignment="Left" Width="452"   />
<TextBox  Name="txtWdith"   Width ="30"   Height="23" Margin="211,149.86,6,188.5" Grid.Row="1"   />

我做错了什么?

但是当你看到文本框没有正确显示时,列表视图应该与向上移动按钮的顶部对齐winforms我原谅你仍然爱你。

<Grid Margin="0,20,0,0" VerticalAlignment="Top" Height="400">
    <Grid.RowDefinitions>
        <RowDefinition Height="28" />
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="100"/>
        <ColumnDefinition Width="100"/>
    </Grid.ColumnDefinitions>
    <Label Grid.Row="0" Content="Custom Fields" Margin="12,0,0,0" Grid.ColumnSpan="2"></Label>
    <StackPanel Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" Grid.ColumnSpan="2">
        <Expander Margin="0,0,0,0" 
          IsExpanded="true" 
            Header="Custom Columns">
            <Grid Margin="12,0,10,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="38.64" />
                    <RowDefinition Height="361.36"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="400"/>
                    <RowDefinition Height="400"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="247" />
                    <ColumnDefinition Width="205"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />

                </Grid.ColumnDefinitions>

                <ListView    Name="listView1"
            MinHeight="80" 
            SelectionMode="Single" Margin="0,11.36,0,108.4" SelectionChanged="listView1_SelectionChanged" Grid.Row="1" Grid.ColumnSpan="2">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Order" Width="100" 
                       DisplayMemberBinding="{Binding Path=CustomColumnsOrder}"></GridViewColumn>
                            <GridViewColumn Header="Display Name" Width="290" 
                          DisplayMemberBinding="{Binding Path=CustomColumnsDisplayName}"></GridViewColumn>
                            <GridViewColumn Header="Width" Width="50" 
                        DisplayMemberBinding="{Binding Path=CustomColumnsWidth}"></GridViewColumn>

                        </GridView>
                    </ListView.View>
                </ListView>

                <Label Content="Name:" Grid.ColumnSpan="2"  />

                <TextBox   Name="txtDsiplayName" Text="{Binding Path=CustomColumnsDisplayName, Mode=TwoWay}"   Height="23"   
            Width="452" Margin="0,149.86,0,188.5"    Grid.ColumnSpan="2"  />
                <Label Content="Width:" Height="400" VerticalAlignment="Bottom" Grid.ColumnSpan="2" HorizontalAlignment="Left" Width="452"   />
                <TextBox  Name="txtWdith"   Width ="30"   Height="23" Margin="211,149.86,6,188.5" Grid.Row="1"   />

                <StackPanel Grid.Column="3" Grid.Row="2" Margin="0,0,74,0" Grid.RowSpan="2"/>

                <StackPanel Grid.Column="2" Margin="0" Grid.RowSpan="2" Grid.ColumnSpan="2">
                    <Button Name="moveUpButton"     Click="MoveUp"     DockPanel.Dock="Right" Content="Move Up" 
            Height="22" Width="74"  />

                    <Button Name="moveDownButton"   Click="MoveDown"    DockPanel.Dock="Right" Content="Move Down" 
            Height="22" Width="74"  />


                    <Button Name="deleteButton" IsEnabled="{Binding ElementName=columnsList, Path=SelectedItems.Count}" Click="RemoveColumn"   DockPanel.Dock="Right" Content="Delete" 
            Height="22" Width="74"  />

                    <Button Name="addButton" Click="AddColumn"       Content="Add Item" 
            Height="22" Width="74" />

                </StackPanel>

            </Grid>
        </Expander>
    </StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:0)

看起来网格行高度和文本框边距相互冲突,如果从文本框中删除边距线,您应该看到它移到顶部。

我建议删除边距,然后尝试使用高度来定位控件。

这样的事可能吗? (您需要在高度/宽度等方面添加,但它会给您一个粗略的想法)

    <Grid VerticalAlignment="Top">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Label Content="Custom Fields" />
    <StackPanel Grid.Row="1" VerticalAlignment="Top">
        <Expander Header="Custom Columns" IsExpanded="true">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <ListView Name="listView1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" SelectionMode="Single">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn DisplayMemberBinding="{Binding Path=CustomColumnsOrder}" Header="Order" />
                            <GridViewColumn DisplayMemberBinding="{Binding Path=CustomColumnsDisplayName}" Header="Display Name" />
                            <GridViewColumn DisplayMemberBinding="{Binding Path=CustomColumnsWidth}" Header="Width" />
                        </GridView>
                    </ListView.View>
                </ListView>

                <StackPanel Grid.Row="1" Grid.RowSpan="2" Grid.Column="3">
                    <Button Name="moveUpButton" Content="Move Up" DockPanel.Dock="Right" />

                    <Button Name="moveDownButton" Content="Move Down" DockPanel.Dock="Right" />

                    <Button Name="deleteButton" Content="Delete" DockPanel.Dock="Right" IsEnabled="{Binding ElementName=columnsList, Path=SelectedItems.Count}" />

                    <Button Name="addButton" Content="Add Item" />
                </StackPanel>

                <Label Grid.Row="3"
                       Grid.Column="0"
                       Grid.ColumnSpan="2"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Bottom"
                       Content="Name:" />
                <TextBox Name="txtDsiplayName" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding Path=CustomColumnsDisplayName, Mode=TwoWay}" />

                <Label Grid.Row="4"
                       Grid.Column="0"
                       Grid.ColumnSpan="2"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Bottom"
                       Content="Width:" />
                <TextBox Name="txtWdith" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" />

            </Grid>
        </Expander>
    </StackPanel>
</Grid>