0
我是Windows商店應用程序的絕對初學者,今天我試圖在我嘗試創建的應用程序中添加ScrollViewer。所以,當我運行下面的代碼左欄中需要90%的屏幕寬度,右列將寬度的10%:將ScrollViewer添加到它時,網格更改寬度
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Header" FontFamily="Segoe UI" FontSize="50" VerticalAlignment="Center" FontStyle="Italic"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="SubHeader :" VerticalAlignment="Bottom" FontFamily="Segoe UI" FontSize="30" FontStyle="Italic"/>
</Grid>
<Grid Grid.Row="1" Background="Transparent" HorizontalAlignment="Left" Height="526" Margin="90,60,0,0" VerticalAlignment="Top">
<TextBlock FontSize="50" Text="This is left Column"/>
</Grid>
</Grid>
<Grid Grid.Column="1">
<Grid Width="800">
<Grid.Background>
<SolidColorBrush Color="Gray" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Heading" FontFamily="Segoe UI" FontSize="40" Margin="80,36,0,0" FontStyle="Italic" Foreground="Black"/>
<Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock FontFamily="Segoe UI" FontSize="30" Text="This is Right Column" Margin="60,0,0,0" Foreground="Black"/>
</Grid>
</Grid>
</Grid>
</Grid>
但是當我添加的ScrollViewer它左邊的列的寬度減小和右寬度列增加。
<ScrollViewer HorizontalAlignment="Left" Margin="0" HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto" VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Disabled">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Header" FontFamily="Segoe UI" FontSize="50" VerticalAlignment="Center" FontStyle="Italic"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="SubHeader :" VerticalAlignment="Bottom" FontFamily="Segoe UI" FontSize="30" FontStyle="Italic"/>
</Grid>
<Grid Grid.Row="1" Background="Transparent" HorizontalAlignment="Left" Height="526" Margin="90,60,0,0" VerticalAlignment="Top">
<TextBlock FontSize="50" Text="This is left Column"/>
</Grid>
</Grid>
<Grid Grid.Column="1">
<Grid Width="800">
<Grid.Background>
<SolidColorBrush Color="Gray" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Heading" FontFamily="Segoe UI" FontSize="40" Margin="80,36,0,0" FontStyle="Italic" Foreground="Black"/>
<Grid Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock FontFamily="Segoe UI" FontSize="30" Text="This is Right Column" Margin="60,0,0,0" Foreground="Black"/>
</Grid>
</Grid>
</Grid>
</Grid>
</ScrollViewer>
我想我添加scrollviewer的方式是錯誤的。任何人都可以請指導我如何在這段代碼中添加水平scrollviewer?
好吧,我明白了,但是當我運行代碼時,一個微小的滾動條只能在右欄中看到。通常單個滾動器覆蓋屏幕的總寬度,但在此代碼中,滾動器僅在右列中可見。 –
如果您需要單個滾動查看器,則需要爲列設置固定寬度 – kskyriacou