您是否考慮將文本框的可見性設置爲Hidden
?這將「隱藏」分配給文本框的空間。假設它們在StackPanel中沒有其他控件,那麼它將不可見。
當然,這個解決方案可能會對您的實現做出一些天真的假設。
如果您需要更復雜的情況下,我會嘗試以下操作: 注:這是僞碼 - 可能無法編譯..
1)使用MultiBinding
<StackPanel>
<StackPanel.Visibility Converter={StaticResource visibilityConverter}>
<MultiBinding.Bindings>
<Binding ElementName="textBox1" Path="Visibility" />
<Binding ElementName="textBox2" Path="Visibility" />
<Binding ElementName="textBox3" Path="Visibility" />
</MultiBinding.Bindings>
</StackPanel.Visibility>
</StackPanel>
2)聲明轉換器
<Window.Resources>
<local:VisibilityConverter x:Key="visibilityConverter" />
</Window.Resources>
3)定義的轉換器
public class VisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Visibility text1Vis = (Visibility)values[0];
Visibility text2Vis = (Visibility)values[1];
Visibility text3Vis = (Visibility)values[2];
if (text1Vis == text2Vis == text3Vis == Visibility.Collapsed)
return Visibility.Collapsed;
return Visibility.Visible;
}
}
小錯誤:轉換器= {StaticResource的visibilityConverter}應該繼續MultiBinding.Bindings代替能見度 – 2010-05-10 20:37:12