WPF الشبكة - السيارات العمود الحجم لا تنهار عندما محتوى الرؤية المقرر أن Visibility.Collapsed

StackOverflow https://stackoverflow.com/questions/1601171

  •  05-07-2019
  •  | 
  •  

سؤال

ولدي simpl برنامج الأغذية العالمي شبكة التالية، عمودين، زر في كل عمود، الحجم أول السيارات عمود والخائن للسماح العمود تغيير الحجم. تعيين معالج الحدث حتى على الخائن الحدث MouseDoubleclick. عندما الخائن هو doulble النقر تم طي الزر في العمود الأيسر.

والآن، والعمود 1 هي السيارات الحجم وانهار محتوى أتوقع في هذه المرحلة أن العمود 1 يجب أن تكون مخفية بشكل فعال، ولكن الأمر ليس كذلك. على الرغم من أن انهار محتواه لا يتغير حجم العمود (وautosized العمود نتذكر).

ويبدو غريبا بالنسبة لي، أود العمود للانهيار - أي فكرة عما يحدث هنا

<Window x:Class="KingLayout.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>
        <Button x:Name="leftButton">Left</Button>
        <Button Grid.Column="1" Margin="5,0,0,0">Right</Button>
        <GridSplitter Name="verticalSplitter" ShowsPreview="True" Grid.RowSpan="1" Grid.Column="1" HorizontalAlignment="Left"
                      VerticalAlignment="Stretch" Width="5" MouseDoubleClick="verticalSplitter_MouseDoubleClick"/>
    </Grid>
</Window>


    private void verticalSplitter_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        leftButton.Visibility = leftButton.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
    }
هل كانت مفيدة؟

المحلول

وما يحدث هو أنه عند تغيير حجم العمود / الصف العرض / الارتفاع مع GridSplitter، يقوم بتعيين ActualHeight (أو ActualWidth) العمود / صف واحد.

ويجب عليك استخدام مشغل لضبط ارتفاع الصف لصناعة السيارات (أو صفر) عندما انهار التحكم الخاصة بك.

والحصول على لي مع تحديث هذا.

نصائح أخرى

في حالتي، وكنت قادرا على استخدام StackPanels ووضع Visibility="Collapsed" التي تسبب بها لتغيير حجم بشكل صحيح.

<StackPanel Orientation="Vertical" Margin="5">
    <StackPanel Orientation="Horizontal">
      <!-- Some controls -->
    </StackPanel>
    <StackPanel Orientation="Horizontal" Visibility="{Binding YourVisibilityProperty}">
      <!-- Some controls -->
    </StackPanel>
</StackPanel>

وذلك لأن الخائن يبقى موقعها في الشبكة، فإنه يسحب العمود الأول، لماذا لا تحاول المتوسع؟

<Grid ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Expander ExpandDirection="Left">
        <Button x:Name="leftButton">Left</Button>
    </Expander>
    <Button Grid.Column="1" Margin="5,0,0,0">Right</Button>
</Grid>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top