1

任何人都可以幫助我在我的項目中執行垂直滾動嗎?我無法這樣做,有人可以幫助我做到這一點?這是我的XAML代碼如何添加垂直滾動到我的內容

<Grid x:Name="LayoutRoot" Background="Black"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 

    <!--TitlePanel contains the name of the application and page title--> 
    <StackPanel Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock Text="Launchers" Grid.ColumnSpan="2" Margin="9,-12,-236,0" Style="{StaticResource PhoneTextTitle1Style}" Height="85" Foreground="White" FontWeight="ExtraBold" FontStretch="SemiCondensed"/> 
    </StackPanel> 

    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"/> 
     <toolkit:HubTile x:Name="GuidanceButton" HorizontalAlignment="Left" 
     VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" Background="#FF12AFC7" GroupTag="StaticHubTile" Tap="Button_gridbut_Click" Margin="30,10,0,0" Size="Medium" Source="/Images/sharemedium.png" /> 
     <toolkit:HubTile x:Name="JourneyButton" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" Background="#FF12AFC7" GroupTag="StaticHubTile" Height="169" Width="169" Margin="72,230,-1,0" Grid.ColumnSpan="2" Tap="Button_gridbut_Click" Source="/Images/facebook.png"/> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="0" Grid.Row="2" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,99,-1,0" Height="82" Width="82"/> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,45,148,0" Height="82" Width="82"/> 
     <toolkit:HubTile x:Name="searchButton" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" Background="#FF12AFC7" GroupTag="StaticHubTile" Size="Default" Margin="0,137,61,0" Grid.RowSpan="2" Height="169" Width="169" Tap="Button_gridbut_Click" Source="/Images/camera.png" /> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,7,148,0" Height="82" Width="82"/> 
     <toolkit:HubTile x:Name="routeButton1" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Background="#FF12AFC7" GroupTag="StaticHubTile" Size="Default" Margin="0,99,61,0" Grid.RowSpan="2" Height="169" Width="169" Tap="Button_gridbut_Click" Source="/Images/status.png" /> 
    </Grid> 
</Grid> 

回答

1

如果您使用的是WinForm的你可以用垂直滾動功能,這樣做是爲了設置您的面板:

ScrollBar vScrollBar1 = new VScrollBar(); 
vScrollBar1.Dock = DockStyle.Right; 
vScrollBar1.Scroll += (sender, e) => { panel1.VerticalScroll.Value = vScrollBar1.Value; }; 
panel1.Controls.Add(vScrollBar1); 

另外,你可以閱讀這篇文章有關添加垂直滾動條在面板:

Vertical ScrollBar in C#

+0

我只想爲我的所有焦點啓用垂直滾動,因爲在屏幕較小的手機中。該應用程序將不夠支持。那麼,你能告訴我在我的代碼中可以執行哪些更改以執行必要的操作嗎? – Priyanshu

0

只需包裝在像ScrollViewer滾動控制滾動內容:

<!--ContentPanel - place additional content here--> 
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"/> 
    <ScrollViewer> 
     <toolkit:HubTile x:Name="GuidanceButton" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" Background="#FF12AFC7" GroupTag="StaticHubTile" Tap="Button_gridbut_Click" Margin="30,10,0,0" Size="Medium" Source="/Images/sharemedium.png" /> 
     <toolkit:HubTile x:Name="JourneyButton" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" Background="#FF12AFC7" GroupTag="StaticHubTile" Height="169" Width="169" Margin="72,230,-1,0" Grid.ColumnSpan="2" Tap="Button_gridbut_Click" Source="/Images/facebook.png"/> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="0" Grid.Row="2" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,99,-1,0" Height="82" Width="82"/> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,45,148,0" Height="82" Width="82"/> 
     <toolkit:HubTile x:Name="searchButton" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" Background="#FF12AFC7" GroupTag="StaticHubTile" Size="Default" Margin="0,137,61,0" Grid.RowSpan="2" Height="169" Width="169" Tap="Button_gridbut_Click" Source="/Images/camera.png" /> 
     <toolkit:HubTile HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Background="#FF298391" GroupTag="StaticHubTile" Size="Small" Margin="0,7,148,0" Height="82" Width="82"/> 
     <toolkit:HubTile x:Name="routeButton1" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Column="1" Grid.Row="2" Background="#FF12AFC7" GroupTag="StaticHubTile" Size="Default" Margin="0,99,61,0" Grid.RowSpan="2" Height="169" Width="169" Tap="Button_gridbut_Click" Source="/Images/status.png" /> 
    </ScrollViewer> 
</Grid> 

而且,由於你不使用它刪除最後一個RowDefinition,它會破壞你的看法了一半。

相關問題