c# wpf 滚动条问题
我在grid上创建100个控件,现在初始化时只能显示一部分,但现在滚动条是灰的,不可用。
我想拖动滚动条,让100个控件可以滚动显示,如何修改?
这是xml:
<Window x:Class="WpfApplication5.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">
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" Grid.Row="0" Grid.Column="0">
<Grid Name="gridMain">
<Button Content="Button" HorizontalAlignment="Left" Margin="183,89,0,0" VerticalAlignment="Top" Width="238" Height="48"/>
</Grid>
</ScrollViewer>
</Window>
这是程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication5
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 20; j++)
{
Image image1 = new Image();
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"E:\DemoProduct\csharp\asag\asag\立筒-图标.ico");
myBitmapImage.DecodePixelWidth = 100;
myBitmapImage.EndInit();