一直在尋找這4小時,傢伙...我實在不明白這一點(可能是微軟的錯誤?)WPF的DataGrid超出電網
這是我,這一切都只是DataGrid控件好。正如你可以在這個視頻中看到,數據超出了應用程序的邊界(網格和滾動條):
https://goo.gl/photos/YnApkZS7v3uZ4TWX6
因爲這個代碼是使用材料設計庫,我剝離下來,以基礎知識,使任何人都可以試試爲自己。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="EvolvDirectoryCreeper.MainWindow"
Height="700" Width="1000">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto" MinWidth="80"/>
</Grid.ColumnDefinitions>
<Grid Height="180" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2">
<Grid Margin="10,10,100,10">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Grid.Row="0" Margin="4"/>
<TextBox Grid.Column="0" Grid.Row="1" Margin="4"/>
<TextBox Grid.Column="0" Grid.Row="2" Margin="4"/>
<Button Grid.Column="1" Grid.Row="0" Margin="4"/>
<Button Grid.Column="1" Grid.Row="1" Margin="4"/>
<Button Grid.Column="1" Grid.Row="2" Margin="4"/>
</Grid>
</Grid>
<Grid Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Height="40" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="4" Padding="0,15,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
<ProgressBar Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="4" VerticalAlignment="Bottom"/>
<Label Content="Good" Grid.Column="0" Grid.Row="1" Margin="4,30,0,0"/>
<Label Content="Bad" Grid.Column="2" Grid.Row="1" Margin="4,30,0,0"/>
<DataGrid Grid.Column="0" Grid.Row="2"/>
<DataGrid Grid.Column="2" Grid.Row="2" ItemsSource="{Binding Path=BadFoldersHistory}"/>
</Grid>
</Grid>
這是C#:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace EvolvDirectoryCreeper
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
private ObservableCollection<string> m_badFoldersHistory = new ObservableCollection<string>();
public ObservableCollection<string> BadFoldersHistory
{
get { return m_badFoldersHistory; }
set {
m_badFoldersHistory = value;
OnPropertyChanged("BadFoldersHistory");
}
}
public virtual event PropertyChangedEventHandler PropertyChanged;
public virtual void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
private Dispatcher MainWindowDispatcher;
public MainWindow()
{
InitializeComponent();
DataContext = this;
MainWindowDispatcher = Dispatcher;
for (int i = 0; i < 40; i++)
BadFoldersHistory.Add("d");
}
}
}
我已經嘗試過的,而不是 「*」, 「汽車」,每個網格的最後一排,但於事無補。我需要保持這個網格結構來維護材料設計FAB的位置並適當調整大小。 任何幫助將不勝感激!
沒錯!這就是它!謝謝! – SYB
順便說一句,任何對Material Design WPG庫感興趣的人,我都強烈推薦:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit – SYB