Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何停止(或理解为什么)强制执行属性绑定?_C#_Wpf_Data Binding_Telerik Radbutton - Fatal编程技术网

C# 如何停止(或理解为什么)强制执行属性绑定?

C# 如何停止(或理解为什么)强制执行属性绑定?,c#,wpf,data-binding,telerik-radbutton,C#,Wpf,Data Binding,Telerik Radbutton,我有一组基于集合创建的按钮,如下所示: <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,5" MinHeight="30"> <ItemsControl ItemsSource="{Binding Filters}" AlternationCount="{Binding Filters.Count}"> <ItemsControl.ItemsP

我有一组基于集合创建的按钮,如下所示:

<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,5" MinHeight="30">
            <ItemsControl ItemsSource="{Binding Filters}" AlternationCount="{Binding Filters.Count}">
              <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                  <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
              </ItemsControl.ItemsPanel>
              <ItemsControl.ItemTemplate>
                <DataTemplate>
                  <telerik:RadToggleButton Content="{Binding Path=Text}" Margin="0,5,10,5" Padding="10,5" MinWidth="40" Command="{Binding Path=Command}"
                                           IsChecked="{Binding Path=Selected}" IsEnabled="{Binding Path=Enabled}" />
                  <DataTemplate.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                      <Setter Property="Margin" Value="0,0,15,0" />
                    </Trigger>
                  </DataTemplate.Triggers>
                </DataTemplate>
              </ItemsControl.ItemTemplate>
            </ItemsControl>
          </StackPanel>
ItemFilter类非常简单:

   public sealed class ItemFilter : INotifyPropertyChanged
   {
    public event PropertyChangedEventHandler PropertyChanged;

    public string Text { get; set; }
    public RoutedCommand Command { get; set; }

    private bool _Selected;

    public bool Selected
    {
      get { return _Selected; }
      set
      {
        _Selected = value;
        OnPropertyChanged(new PropertyChangedEventArgs("Selected"));
      }
    }

    private bool _Enabled;

    public bool Enabled
    {
      get { return _Enabled; }
      set
      {
        _Enabled = value;
        OnPropertyChanged(new PropertyChangedEventArgs("Enabled"));
      }
    }

    public ItemFilter()
    {
      _Enabled = true;
    }

    private void OnPropertyChanged(PropertyChangedEventArgs args)
    {
      PropertyChanged?.Invoke(this, args);
    }
  }
还有一些其他逻辑,用于在单击每个筛选按钮时,根据一些业务规则管理
选定的
状态。在创建时设置
ItemFilter
集合对象后,当前没有任何内容会修改该集合对象上的
Enabled
属性

问题是,无论我将什么设置为命令、按钮文本、启用属性、选定属性或按钮在集合中的位置,它总是以
enabled=false
-结束,并且仅此按钮的所有其他行为都与预期一致

任何帮助都将不胜感激

更新

我尝试从items控件XAML中删除命令属性和绑定,按钮的启用正如预期的那样

将命令的绑定模式更改为
OneWayToSource
也会正确显示按钮启用,但命令绑定无法按预期工作

更新

相关的
命令
代码如下所示

 public static class Commands
 {
    // all commands for this example follow this pattern
    public static readonly RoutedCommand FilterF = new RoutedCommand("f", typeof(Commands));
 }

它与Commands.FilterF有关。相关代码是什么?有关
命令
代码,请参阅第二次更新。
 public static class Commands
 {
    // all commands for this example follow this pattern
    public static readonly RoutedCommand FilterF = new RoutedCommand("f", typeof(Commands));
 }