DataContext是不可访问的,所以我想绑定不会发生


   <Grid>
      <CheckBox  Content="Select All" IsChecked="{Binding Path=SelectAll}"/>
      <TextBlock Grid.Column="1" Text="Filter by:"  />
      <RadioButton IsChecked="{Binding Path=All}" GroupName="filterGroup" Content="All" />
      <RadioButton IsChecked="{Binding Path=NShared}" GroupName="filterGroup" Content="Not Shared" />
   </Grid>
   <GroupBox Header="Members" Style="{StaticResource CenteredHeaderGroupBoxStyle}" Width="330">
      <GroupBox.HeaderTemplate>
           <DataTemplate>
                <Border Width="320">
                    <Grid HorizontalAlignment="Center" Width="320">
                       <ToggleButton Name="LeftButton" Command="{Binding Path=MemeberButtonSelected}"/>
                       <ToggleButton Name="RightButton" IsChecked="{Binding Path=GroupSelected}"/>
                     </Grid>
                 </Border>
            </DataTemplate>
       </GroupBox.HeaderTemplate>
       <GroupItem>
          <Border>
            <ListBox Name="GroupMemberList">
                <ListBox.Style>
                    <Style>
                       <Style.Triggers>
                           <DataTrigger Binding="{Binding Path=GroupSelected}" Value="True">
                                <Setter Property="ListBox.ItemsSource" Value="{Binding Path=GroupsoftheCase}"/>
                                <Setter Property="ListBox.ItemTemplate" Value="{StaticResource GroupListTemplate}"/>
                                <Setter Property="ListBox.SelectedValue" Value="{Binding Path=SelectedGroups}"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=MemberSelected}" Value="True">
                                <Setter Property="ListBox.ItemsSource" Value="{Binding Path=MembersoftheCase}"/>
                                <Setter Property="ListBox.ItemTemplate" Value="{StaticResource MembersListTemplate}"/>
                                <Setter Property="ListBox.SelectedValue" Value="{Binding Path=SelectedMembers}"/>
                            </DataTrigger>
                       </Style.Triggers>
                    </Style>
                </ListBox.Style>
             </ListBox>
          </Border>
       </GroupItem>
   </GroupBox>

ToggleButton绑定不起作用-属性/命令存在于视图的DataContext中

但是输出显示

System.Windows.Data错误:40:BindingExpression路径错误:在"object"String"(HashCode=-139923548("上找不到"MemeberButtonSelected"属性。BindingExpression:Path=MemeberButtonSelected;DataItem="字符串"(HashCode=-139923548(;目标元素是"ToggleButton"(名称="(;目标属性是"命令"(类型为"ICommand"(


System.Windows.Data错误:40:BindingExpression路径错误:在"object"String"(HashCode=-139923548(上找不到"GroupSelected"属性。BindingExpression:Path=GroupSelected;DataItem="字符串"(HashCode=-139923548(;目标元素是"ToggleButton"(名称="(;目标属性为"IsChecked"(类型为"Nullable"1(

我也试过相对源

作为

 IsChecked="{Binding Path=MemberSelected, RelativeSource={RelativeSource AncestorType={x:Type GroupBox}}}"

对于其中一个Toggle按钮,如果它不使用,则输出中的String将更改为对象,即所有

您的GroupBoxHeader是一个字符串("Members"(,因此HeaderTemplate中的DataContext也是一个字符串。。。并且在类型String上没有MemeberButtonSelected属性。您需要绑定到GroupBox:的DataContext

...
<Grid HorizontalAlignment="Center" Width="320">
   <ToggleButton Name="LeftButton" Command="{Binding Path=DataContext.MemeberButtonSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}}"/>
   <ToggleButton Name="RightButton" IsChecked="{Binding Path=DataContext.GroupSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}}"/>
 </Grid>
...

您要传递到其中的DataContext对象类型是什么?您的输出显示字符串,所以在某些地方您得到了错误的数据。尝试在每个实例之后设置一个断点,在该实例中,将更新绑定到的任何数据。或者,如果您有Mole,您可以使用它直接查看项目数据上下文。

最新更新