Xaml和布局问题
本文关键字:问题 布局 Xaml | 更新日期: 2023-09-27 18:24:52
我正试图使用xaml构建一个屏幕,但它有点偏离了。我还不能上传图像,所以我包含了这个链接。
我的问题是txtWidth文本框在应该足够大到只能容纳3位数字的情况下会从屏幕上消失?有人有什么想法吗。
<Canvas Margin="0,0,-249.6,0">
<ListView Canvas.Left="12" Canvas.Top="48" Height="183" Name="listView1"
Width="453"
SelectionMode="Single">
<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>
<Button Name="moveUpButton" Canvas.Left="472.4" Click="MoveUp" Canvas.Top="50" Content="Move Up"
Height="22" Width="74" />
<Button Name="moveDownButton" Canvas.Left="472.4" Click="MoveDown" Canvas.Top="80" Content="Move Down"
Height="22" Width="74" />
<Button Name="deleteButton" Canvas.Left="472.4" IsEnabled="{Binding ElementName=columnsList, Path=SelectedItems.Count}" Click="RemoveColumn" Canvas.Top="110" Content="Delete"
Height="22" Width="74" />
<Button Name="addButton" Click="AddColumn" Canvas.Left="472.4" Canvas.Top="140" Content="Add Item"
Height="22" Width="74" />
<Label Content="Name:" Canvas.Left="12" Canvas.Top="250" />
<TextBox Name="txtDsiplayName" Text="{Binding Path=CustomColumnsDisplayName, Mode=TwoWay}" Canvas.Left="12" Canvas.Top="280" Height="23"
Width="452" >
</TextBox>
<Label Content="Width:" Canvas.Left="470" Canvas.Top="250" />
<TextBox Name="txtWdith" Text="50" Canvas.Left="470" Canvas.Top="280" Height="23"
/>
</Canvas>
从使用Canvas
布局更改为使用Grid
布局,这里有一个非常好的教程。
网格布局示例如下所示:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="28" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Content="Name:"/>
<Label Grid.Row="1"
Grid.Column="0"
Content="E-Mail:"/>
<Label Grid.Row="2"
Grid.Column="0"
Content="Comment:"/>
<TextBox Grid.Column="1"
Grid.Row="0"
Margin="3" />
<TextBox Grid.Column="1"
Grid.Row="1"
Margin="3" />
<TextBox Grid.Column="1"
Grid.Row="2"
Margin="3" />
<Button Grid.Column="1"
Grid.Row="3"
HorizontalAlignment="Right"
MinWidth="80"
Margin="3"
Content="Send" />
</Grid>