그룹화 항목과 함께 ListView가 있습니다. 그룹화는 사용자 지정 GroupStyle (확장기)을 사용합니다. 나는 모든 그룹을 확장하고 축소 할 수있는 확인란을 갖고 싶습니다. 그룹 헤더를 수동으로 클릭하고 해당 그룹을 확장하거나 축소 할 때까지 제대로 작동합니다. 해당 특정 그룹을 클릭하면 확인란 선택이 취소됩니다. 사용자가 그룹을 수동으로 클릭하면 바인딩이 끊어진 것처럼 보입니다.ElementName ControlTemplate에서 끊어진 바인딩
내가 뭘 잘못하고 있는지 알려주십시오.
고마워요.
감사합니다. 블라드.
<Window xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<Window.Resources>
<XmlDataProvider x:Key="MyData" XPath="/Info">
<x:XData>
<Info xmlns="">
<Item Name="Item 1" Category="Cat1" />
<Item Name="Item 2" Category="Cat1" />
<Item Name="Item 3" Category="Cat2" />
<Item Name="Item 4" Category="Cat2" />
<Item Name="Item 5" Category="Cat2" />
<Item Name="Item 6" Category="Cat3" />
</Info>
</x:XData>
</XmlDataProvider>
<CollectionViewSource x:Key='src' Source="{Binding Source={StaticResource MyData}, XPath=Item}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="@Category" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<ControlTemplate x:Key="ListTemplate" TargetType="ListView">
<ListView BorderThickness="0"
ItemsSource='{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsSource}'
DisplayMemberPath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DisplayMemberPath}">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="{Binding IsChecked, ElementName=chkExpandAll, Mode=OneWay}">
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100" />
<TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}" />
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</ControlTemplate>
</Window.Resources>
<StackPanel>
<CheckBox Name="chkExpandAll" IsChecked="True" Content="Expand All" />
<ListView ItemsSource='{Binding Source={StaticResource src}}' DisplayMemberPath="@Name" BorderThickness="1" Template="{StaticResource ListTemplate}" />
</StackPanel>
</Window>
이 해결 방법은 나에게 적합하지 않습니다. – jpierson
나를 위해 동일합니다. RuntimeException에, 나는 또한 경로를 지정하도록 요청 받았다. 이것은'Path = .'로 설정합니다. 이것은 ErrorTemplate의'PlacementTarget = "{Binding ElementName = ImageAction, Path =., Mode = TwoWay, UpdateSourceTrigger = Explicit} 내 바인딩입니다."''ImageAction' 요소는 customcontrol이며, 샘플에서'chkExpandAll'과 같은 방식으로 추가되었습니다. – LuckyLikey