我有一个后台工作者被调用来做一些工作,在那个后台工作者我想启用一个Button:
myButton.IsEnabled = true;
Run Code Online (Sandbox Code Playgroud)
在我的UI(主线程)中.我需要做什么才能使回调主线程执行此操作?
我有一个带有Grid和TreeView的WPF窗口.Grid的datacontext绑定到树视图上的选定项.但是,因为并非所有treeviewitems都适用,所以如果treviewitem不适用,我想禁用网格.所以,我创建了一个值转换器来进行空检查并返回一个bool.(在这种情况下,适用的项目不会为空)
问题是从未使用过值转换器.我设定了破发点,他们从未被击中过.我有其他价值转换器我正在使用它们都工作得很好.
有什么我想念的吗?
<Grid Grid.Column="1" Grid.Row="0" DataContext="{Binding MyVal}" IsEnabled="{Binding MyVal, Converter={StaticResource NullCheckConverter}}" Margin="2,2,2,2">
Run Code Online (Sandbox Code Playgroud)
并不是说这个问题很重要,但这里是ValueConverter代码:
internal class NullCheckValueConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return !(value == null);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
Run Code Online (Sandbox Code Playgroud) 如何将字符串值绑定Y到NisEnabled 值?
<TextBox IsEnabled="{Binding Path=StringValueFromSomeEntity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
StringValueFromSomeEntity 可以是一个Y或N值。
我希望在我的属性为空时禁用我的网格,并在非空时启用.
在我的.XAML中:
<Grid Grid.Row="2" IsEnabled="{Binding ElementName=dgCustomers, Path=SelectedItem}">
<my:ProductsHistoryDetailView />
</Grid>
Run Code Online (Sandbox Code Playgroud)
在我的ViewModel.cs中:
public ProductHistory SelectedItem
{
get { return _SelectedItem; }
set
{
if (_SelectedItem != value)
{
_SelectedItem = value;
RaisePropertyChanged(() => SelectedItem);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我希望 ComboBox 的 XAML 根据它是否有项目来处理它自己的 IsEnabled 属性。如果后面代码中的 DataTable 返回 Items, id 就像要启用的 ComboBox ,否则如果没有添加任何 Items ,它会保留或成为禁用的控件。这是可能吗?
我当前的组合框设置:
<ComboBox x:Name="ImportDate"
DisplayMemberPath="FileDate"
SelectedValuePath="ID"
ItemsSource="{Binding Mode=OneWay}"
SelectedIndex="0"
Style="{DynamicResource sanComboBox_Standard}" />
Run Code Online (Sandbox Code Playgroud)