我想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();
}
}
uj5u.com熱心網友回復:
iFMaxTextBoxLength在視圖模型中定義,您可以使用RelativeSource屬性系結到它:
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBox}">
<Setter Property="MaxLength"
Value="{Binding DataContext.MaxTextBoxLength,
RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
</Style>
</DataGridTextColumn.EditingElementStyle>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/436551.html
