【发布时间】:2011-05-31 12:29:23
【问题描述】:
<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 路径错误:在“对象”“字符串”(HashCode=-1399923548)上找不到“MemeberButtonSelected”属性。 BindingExpression:Path=MemeberButtonSelected; DataItem='String' (HashCode=-1399923548);目标元素是 'ToggleButton' (Name='');目标属性是“命令”(输入“ICommand”)
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“字符串”(HashCode=-1399923548)上找不到“GroupSelected”属性。 BindingExpression:Path=GroupSelected; DataItem='String' (HashCode=-1399923548);目标元素是 'ToggleButton' (Name='');目标属性为“IsChecked”(类型为“Nullable`1”)
我也尝试过相对来源
作为
IsChecked="{Binding Path=MemberSelected, RelativeSource={RelativeSource AncestorType={x:Type GroupBox}}}"
对于其中一个切换按钮及其不使用仅输出中的字符串将更改为全部对象
【问题讨论】:
-
你确定没有错别字吗?
MemeberButtonSelected看起来像是一个错字。此外,在相对路径示例中,您将其命名为MemberSelected。
标签: .net wpf data-binding binding datatemplate