问题标签 [isenabled]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2103 浏览

c# - WPF 将 IsEnabled 属性绑定到 List 的大小

我想将IsEnabled(功能区按钮的)属性绑定到列表大小。因此,当列表大小 > 0 时IsEnabled,设置为trueelse(如果为 0),则设置为 false。你是怎样做的?

0 投票
4 回答
5560 浏览

c# - WPF - isEnabled 上的 NullReferenceException

我是 WPF 的新手,过去我使用过 Windows 窗体。我在这里遇到一个问题,我希望有人向我解释。下面是一个非常简单的例子。

我有一个 XAML 页面,其中有一个复选框、一个按钮和一个文本字段。默认情况下选中该复选框。

当复选框未选中时,我想启用按钮和文本字段,例如

XAML:

堆栈跟踪:

System.NullReferenceException 未被用户代码处理
Message=Object 引用未设置为对象的实例。
Source=TestProject StackTrace: 在 TestProject.MainWindow.UseDefaultFoldersCB_Checked(Object sender, RoutedEventArgs e) 在 C:\Users\jc\Desktop\Test\TestProject\MainWindow.xaml.cs:line 611 at System.Windows.EventRoute.InvokeHandlersImpl(Object在 System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 在 System.Windows.DependencyObject.OnPropertyChanged 的​​ System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) (DependencyPropertyChangedEventArgs e) 在 System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 在 System.Windows.DependencyObject。NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 在 System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata 元数据, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember) System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) 的对象值、PropertyMetadata 元数据、Boolean coerceWithDeferredReference、Boolean coerceWithCurrentValue、OperationType operationType、Boolean isInternal)属性,对象值)对象值)对象值)UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata 元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔 coerceWithDeferredReference,布尔 coerceWithCurrentValue,OperationType operationType)在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,对象值,PropertyMetadata 元数据,布尔 coerceWithDeferredReference,布尔 coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata 元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔 coerceWithDeferredReference,布尔 coerceWithCurrentValue,OperationType operationType)在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,对象值,PropertyMetadata 元数据,布尔 coerceWithDeferredReference,布尔 coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 在 System.Windows.DependencyObject.SetValue (DependencyProperty dp,对象值)在 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(对象实例,XamlMember 属性,对象值)EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 在 System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 在 System.Windows.DependencyObject.SetValue (DependencyProperty dp,对象值)在 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(对象实例,XamlMember 属性,对象值)Boolean coerceWithDeferredReference、Boolean coerceWithCurrentValue、OperationType operationType、Boolean isInternal) 在 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value) 的 System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)Boolean coerceWithDeferredReference、Boolean coerceWithCurrentValue、OperationType operationType、Boolean isInternal) 在 MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value) 的 System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)

When I launch the application from Visual Studio, I get a NullReferenceException on the above code. Why does this code execute when the application launches? I'd have thought it would only execute when the checkbox is checked/unchecked? Why the NullReferenceException?

Thanks.

0 投票
1 回答
2842 浏览

c# - Wpf:在中断样式触发器的代码中设置 IsEnabled

使用 DataTrigger 操作控件的 IsEnabled 属性时遇到问题。通常它工作正常,但是当我在视图的 Initialized 事件中初始化 IsEnabled 状态时,动态样式化不再起作用。

这是我的代码。我将其精简为最简单的示例。

为什么会发生这种情况,我该怎么做才能通过样式触发器和在后面的代码中对其进行初始化来设置 IsEnabled?

提前致谢!

看法:

(包含一个文本框,应根据复选框的值启用/禁用)

查看代码隐藏:

(唯一的补充是为 IsEnabled 设置初始状态的 Initialized 事件的实现)

视图模型:

(ViewModelBase 持有 INotifyPropertyChanged 接口的实现)

0 投票
2 回答
629 浏览

c# - 无法将 RibbonTextBox isEnable 设置为 False

我一直在尝试功能区控件并遇到了一个可能的错误(或者我可能做错了什么)。如果我有一个RibbonTextBoxRibbonTab并且在后面的代码中将isEnabled设置为FalseTrue,我只能将其设置为 false 而不能设置为 true。其余RibbonTextBox被禁用。

0 投票
2 回答
2715 浏览

wpf - 侦听 Wpf 元素上 IsEnabled 的更改

我想监听 WPF 元素上 IsEnabled 属性的更改(以便我可以在它更改时运行一些通用代码),而不必在每个窗口/页面中放置大量代码。

我还想避免由于强大的事件侦听器而导致内存泄漏的任何潜在问题。我遇到过一些建议使用弱事件侦听器等的文章,但这对于看起来应该非常简单的事情来说似乎非常复杂。

我不想为了做到这一点而对控件进行子类化,因为我想监听 IsEnabled 更改的几种控件类型(将来可能还会更多)。

有没有人想出一个更整洁的方法来处理这个?

0 投票
2 回答
6797 浏览

wpf - IsEnabled False 如果 Binding.Source 不可用

如果绑定值为 false 或 null,则有一个我想要禁用的按钮。这是我试过的。

我有一个 SearchItem.WFBatchFolderStatus 可以为空的情况(并且出于有效的商业原因)。如果 SearchItem.WFBatchFolderStatus 为空,那么我希望禁用该按钮。当 SearchItem.WFBatchFolderStatus 为 null 时,转换器不会触发。如果 SearchItem.WFBatchFolderStatus 不为空,则转换器触发。如果值为 null,则转换器仅返回 false,否则返回该值。但是转换器永远不会看到空值。当 SearchItem.WFBatchFolderStatus 为空时,按钮已启用(不是我想要的)。如果我删除 TargetValue 和/或 Converter,则当 SearchItem.WFBatchFolderStatus 为空时,按钮仍处于启用状态。

0 投票
3 回答
473 浏览

wpf - 控件之间的 WPF 依赖关系

我有 3 个文本框,它们的可见性取决于复选框。我想在所有文本框上设置 IsEnabled = false,当 checkbox.IsChecked = false 和 IsEnabled = true 时 IsChecked = true。如何在 XAML 中实现这种依赖关系?

谢谢。

0 投票
3 回答
8750 浏览

wpf - IsEnabled 时更改按钮图像

我想在按钮时更改按钮图像IsEnabled == False

下面是我的示例,绑定很好,当我更改它们时False/True它仍然无法正常工作。

0 投票
1 回答
1125 浏览

wpf - IsEnabled 为 false 时 ListView 周围的边框

当设置IsEnabledFalseon时,ListView我在控件周围得到一个像素厚的边框,带有颜色#F0F0F0(在 Win7 上)。

我怀疑这是其中之一SystemColors。如何将此边框设置BorderThickness0,或者如果不这样SystemColors做,我应该在我的样式中覆盖哪一个以将其更改为与控件背景相同?

我确定这里有多余的行,因为我一直在添加和删除试图解决问题的东西

0 投票
2 回答
6086 浏览

wpf - 将 IsEnabled 的约定添加到 Caliburn.Micro

如何IsEnabled为控件的属性向 Caliburn.Micro 添加自定义约定 - 例如在 TextBox 上并行绑定到NameEnabled绑定到。IsEnabledNameText

在某种程度上,我想要实现的类似于CanSave可以使用属性来启用/禁用绑定到Save方法的按钮的方式,但对于所有控件都是通用的。