动态设置 DataGridTextColumn MaxLength 属性
我想根据整数变量动态设置 DataGridTextColumn.MaxLength
属性。因此,在某些情况下它应该是 4,而在其他情况下它应该是 5。
我尝试使用 MaxLength
值的绑定,如下所示:
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<Setter Property="MaxLength" Value="{Binding MaxTextBoxLength, UpdateSourceTrigger=PropertyChanged}"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
public int MaxTextBoxLength
{
get => maxTextBoxLength;
set
{
maxTextBoxLength= value;
RaisePropertyChanged();
}
}
I want to set the DataGridTextColumn.MaxLength
property dynamically based on an integer variable. Therefore, in some cases it should be 4 and in others it should be 5.
I tried it with a binding on the MaxLength
value like this:
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<Setter Property="MaxLength" Value="{Binding MaxTextBoxLength, UpdateSourceTrigger=PropertyChanged}"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
public int MaxTextBoxLength
{
get => maxTextBoxLength;
set
{
maxTextBoxLength= value;
RaisePropertyChanged();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
MaxTextBoxLength
在视图模型中定义,您可以使用RelativeSource
属性绑定到它:iF
MaxTextBoxLength
is defined in the view model, you could bind to it using theRelativeSource
property: