I have a business requirement that when the user clicks a series of checkboxes in a WPF application that it will show panels depending upon what checkboxes they select. I would like to use the expander panel but I am not sure how to hide the header. The user should not be allowed to see it unless they check the checkbox. Does anyone know?
我有一个业务要求,当用户单击WPF应用程序中的一系列复选框时,它将显示面板,具体取决于他们选择的复选框。我想使用扩展器面板,但我不知道如何隐藏标头。除非他们选中复选框,否则不应允许用户查看它。有人知道吗?
3 个解决方案
#1
4
You can do this via making a custom Style for your Expander.
您可以通过为扩展器创建自定义样式来完成此操作。
However, it might be easier to just place the controls in a different panel, and set it's visibility to Collapsed in response to the check box state. The main reason to use Expander is specifically to have the header and controls.
但是,将控件放在不同的面板中可能更容易,并将其可见性设置为Collapsed以响应复选框状态。使用Expander的主要原因是具有标题和控件。
#2
2
While not the ideal approach you could go this route...
虽然不是理想的方法,你可以走这条路......
<Expander>
<Expander.Header>
<TextBlock Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}, Mode=FindAncestor},
Converter={StaticResource BoolToVisibilityConverter}}">My Expander</TextBlock>
</Expander.Header>
</Expander>
...where BoolToVisibilityConverter
is something like...
...... BoolToVisibilityConverter就像......
public class BoolToVisibilityConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return Visibility.Visible;
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((Visibility)value == Visibility.Visible)
return true;
return false;
}
#endregion
}
#3
0
This answer has all that you need: WPF Expander Button Styled so it is inside Expander Header
这个答案有你需要的所有东西:WPF扩展器按钮样式,所以它在扩展器标题内
If you use the style he mentions and set no header content, the header disappears
如果你使用他提到的样式并且没有设置标题内容,则标题会消失
#1
4
You can do this via making a custom Style for your Expander.
您可以通过为扩展器创建自定义样式来完成此操作。
However, it might be easier to just place the controls in a different panel, and set it's visibility to Collapsed in response to the check box state. The main reason to use Expander is specifically to have the header and controls.
但是,将控件放在不同的面板中可能更容易,并将其可见性设置为Collapsed以响应复选框状态。使用Expander的主要原因是具有标题和控件。
#2
2
While not the ideal approach you could go this route...
虽然不是理想的方法,你可以走这条路......
<Expander>
<Expander.Header>
<TextBlock Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}, Mode=FindAncestor},
Converter={StaticResource BoolToVisibilityConverter}}">My Expander</TextBlock>
</Expander.Header>
</Expander>
...where BoolToVisibilityConverter
is something like...
...... BoolToVisibilityConverter就像......
public class BoolToVisibilityConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return Visibility.Visible;
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((Visibility)value == Visibility.Visible)
return true;
return false;
}
#endregion
}
#3
0
This answer has all that you need: WPF Expander Button Styled so it is inside Expander Header
这个答案有你需要的所有东西:WPF扩展器按钮样式,所以它在扩展器标题内
If you use the style he mentions and set no header content, the header disappears
如果你使用他提到的样式并且没有设置标题内容,则标题会消失