2012-05-17 31 views
5

Aşağıdaki XAML ile onay kutusunun işaretini kaldırdığınızda alt satır gizlenir. Gridsplitter ile yeniden boyutlandırana kadar her şey iyi. Ardından onay kutusunu işaretleyin/işaretini kaldırın hiçbir şey yapmaz. Dönüştürücünün Yüksekliği 0'a ayarladığı göz önüne alındığında, satırın gizlenmesini bekledim. Neler oluyor? Ayırıcıyı taşıdıktan sonra yükseklikleri nasıl sıfırlayabilirim?Bölücü kullandıktan sonra ızgara sırası yüksekliği nasıl sıfırlanır?

<Grid> 
    <Grid.Resources> 
     <m:CheckedToLengthConverter x:Key="checkedToLengthConverter" /> 
    </Grid.Resources> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="3*" /> 
     <RowDefinition Height="{Binding Mode=OneWay, ElementName=ShowBottomCheckBox, Path=IsChecked, Converter={StaticResource checkedToLengthConverter}, ConverterParameter=2}" /> 
    </Grid.RowDefinitions> 
    <Border Background="Blue" /> 
    <CheckBox Name="ShowBottomCheckBox" IsChecked="True" /> 
    <GridSplitter HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="5" /> 
    <Border Background="Red" Grid.Row="1" /> 
</Grid> 

Dönüştürücü:

public class CheckedToLengthConverter: IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     if ((bool)value) 
      return new GridLength(int.Parse(parameter.ToString()), GridUnitType.Star); 

     return new GridLength(0, GridUnitType.Pixel); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

cevap

4

sorun splitter hareket kez ilk satır yüzden herhangi bir etkisi olmayacaktır geri * Son satır ayarlayarak, açık bir genişliğe sahip olmasıdır. Bazı deneylerden sonra aşağıdaki kodla geldim. TwoWay ciltleme belirtmeniz gerektiğini veya işe yaramadığını unutmayın.

public class CheckedToLengthConverter : MarkupExtension, IValueConverter 
{ 
    public GridLength TrueValue { get; set; } 
    public GridLength FalseValue { get; set; } 

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     return System.Convert.ToBoolean(value) ? TrueValue : FalseValue; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     return Binding.DoNothing; 
    } 

    #region Overrides of MarkupExtension 

    public override object ProvideValue(IServiceProvider serviceProvider) 
    { 
     return this; 
    } 

    #endregion 
} 

<Grid> 
    <Grid.Resources> 
     <m:CheckedToLengthConverter TrueValue="2*" FalseValue="*" x:Key="c1" /> 
     <m:CheckedToLengthConverter TrueValue="3*" FalseValue="0" x:Key="c2" /> 
    </Grid.Resources> 

    <Grid.RowDefinitions> 
     <RowDefinition Height="{Binding Mode=TwoWay, Path=IsChecked, 
         ElementName=ShowBottomCheckBox, 
         Converter={StaticResource c1}}"/> 
     <RowDefinition Height="auto"/> 
     <RowDefinition Height="{Binding Mode=TwoWay, Path=IsChecked, 
         ElementName=ShowBottomCheckBox, 
         Converter={StaticResource c2}}"/> 
    </Grid.RowDefinitions> 
    <Border Background="Blue" /> 
    <CheckBox Name="ShowBottomCheckBox" IsChecked="True" /> 
    <GridSplitter HorizontalAlignment="Stretch" 
        Grid.Row="1" VerticalAlignment="Bottom" Height="5" 
        ResizeBehavior="PreviousAndNext" /> 
    <Border Background="Red" Grid.Row="2" /> 
</Grid> 
+0

Bir örnek verebilir misiniz? Çalışamıyorum. – Manuel

+0

@Manuel, Benim için çalışan bir şey yarattım. – Phil

-1

Bu UX sorunu değil çocuklar, kod değil. Yapmaya çalıştığınız şey mantıklı değil, bunun yerine Visual States kullanmayı denediniz mi?

İlgili konular