gpt4 book ai didi

c# - 按钮 IsEnabled 永远不会改变

转载 作者:太空狗 更新时间:2023-10-29 22:26:04 24 4
gpt4 key购买 nike

这是我的 Button 声明,用 .xaml 文件编写:

<dxlc:LayoutGroup Orientation="Horizontal"  Margin="5,15,0,5">
<Grid MinWidth="100">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button
IsEnabled="{Binding IsSearchCriteriaHasValue}"
Content="Search"
MaxHeight="25"
MaxWidth="70"
ClipToBounds="True"
VerticalAlignment="Center"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Command="{Binding SearchCommand}"/>
</Grid>
</dxlc:LayoutGroup>

无论用户是否在搜索按钮旁边的搜索框中键入了任何搜索文本,该函数都会返回 true/false。该函数在另一个 .cs 文件中:

public bool isButtonEnabled
{
return (SearchBox.Selection.Count > 0);
}

问题是 isEnabled 的值永远不会改变,它保持为真,即按钮始终保持启用状态,或者如果我更改 > 符号,按钮始终保持禁用状态。有什么建议吗?

最佳答案

IsSearchCriteriaHasValue 需要引发它更改的事件,您可以使用 INotifyPropertyChanged 接口(interface)来实现:

public class Customer : INotifyPropertyChanged
{
// INotifyPropertyChanged members
public event PropertyChangedEventHandler PropertyChanged;

public void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}

// Your property
private string _Name;

public string Name
{
get
{
return _Name;
}
set
{
_Name = value;
OnPropertyChanged(new PropertyChangedEventArgs("Name"));
}
}
}

关于c# - 按钮 IsEnabled 永远不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31452734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com