问题描述
您好,最近我一直在困扰一个设计问题,希望您能为我提供帮助.
Hi there, I have been messing with a design problem these days and I hope you could help me.
我有一个带有GroupStyle的ListView,可以正确显示它,但是当我尝试使用转换器更改Expander样式时,我的问题来了.
I have a ListView with a GroupStyle which is correctly shown but my problem comes when I try to change the Expander style with a converter.
- 这就是我定义GroupStyle的方式("ar"是样式的数组)
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="False" Style="{Binding Path=state,
Converter={StaticResource InverseConditionalSetterConverter},
ConverterParameter={StaticResource ar}
}">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="12" VerticalAlignment="Bottom" />
</StackPanel> </Expander.Header>
</StackPanel> </Expander.Header>
< ItemsPresenter/> </Expander> </ControlTemplate> </Setter.Value> </Setter> </样式> </GroupStyle.ContainerStyle> </GroupStyle> </ListView.GroupStyle>
<ItemsPresenter /> </Expander> </ControlTemplate> </Setter.Value> </Setter> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </ListView.GroupStyle>
- 这是我的转换器.
public class ConditionalSetterConverter : IValueConverter
{
public int Inverse { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Style[] s = parameter as Style[];
switch ((int)value)
{
case 1:
return s[0];
case 2:
return s[1];
default:
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
如果我将此转换器与普通扩展器(在组外)一起使用,则该转换器可以工作.
If I use this converter with a normal Expander (outside the group), the converter works.
推荐答案
您有对InverseConditionalSetterConverter的引用,但该转换器被命名为ConditionalSetterConverter. 您的XAML中有一个ConverterParameter,但您显示的转换器使用的值未在 XAML.
You have a reference to InverseConditionalSetterConverter yet the converter is named ConditionalSetterConverter. You have a ConverterParameter in your XAML but the converter you show uses a value which is not set in anything that is show in the XAML.
如果您需要帮助,请向我们显示更多信息并向我们显示相关信息,以便我们提供帮助.
If you want help please show us more and show us related information so that we might help.
这篇关于通过ListView GroupStyle内的Converter修改Expander样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!