/ / WPF Window with 3 Grid - c #, .net, wpf

Finestra WPF con 3 Grid - c #, .net, wpf

Voglio costruire application che nella finestra principale ne ho 3 Grid e 2 GridSplitter fra loro:

<Window x:Class="PlayTube.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="625">
<Grid Background="#FFD86F6F">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid Background="#FFFFFF89" MaxWidth="200">

</Grid>

<GridSplitter HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Grid.Column="1" ResizeBehavior="PreviousAndNext"
Width="5" Background="#FFBCBCBC" />

<Grid Background="#FF05BECB" Grid.Column="2">

</Grid>

<GridSplitter HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Grid.Column="3" ResizeBehavior="PreviousAndNext"
Width="5" Background="#FFBCBCBC"/>

<Grid Background="#FF4E04A7" Grid.Column="4">

</Grid>
</Grid>
</Window>

E voglio che le prime due Griglie abbiano una larghezza massima di 200 px. e quando provo a ridimensionare con GridSplitter la griglia rimane al massimo 200 ma posso vedere il colore della griglia principale.

Qualche idea di qual è il problema?

risposte:

2 per risposta № 1

Prova a spostare la proprietà MaxWidth su ColumnDefinition anziché sulla griglia.

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="625">
<Grid Background="#FFD86F6F">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" MaxWidth="200"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Grid Background="#FFFFFF89" >

</Grid>

<GridSplitter HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Grid.Column="1" ResizeBehavior="PreviousAndNext"
Width="5" Background="#FFBCBCBC" />

<Grid Background="#FF05BECB" Grid.Column="2">

</Grid>

<GridSplitter HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Grid.Column="3" ResizeBehavior="PreviousAndNext"
Width="5" Background="#FFBCBCBC"/>

<Grid Background="#FF4E04A7" Grid.Column="4">

</Grid>
</Grid>
</Window>