如何从textbox tbUser获取代码输入?
我需要使用该输入来处理后面的代码,并且我得到 tbUser
不存在的错误。
<DataGridTextColumn Binding="{Binding User Name}" Width="130" MinWidth="130" MaxWidth="150">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBox BorderBrush="Black" BorderThickness="1" Margin="1"
Name="tbUser" Width="117" MinWidth="117" MaxWidth="147"/>
<TextBlock Text="User Name" Margin="1" FontWeight="DemiBold"
TextWrapping="Wrap" TextAlignment="Left"/>
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
答案 0 :(得分:0)
您可以将DataGridTextColumn.HeaderTemplate
更改为DataGridTextColumn.Header
,因为您只将此模板用于此列,并且不会覆盖ControlTemplate
。
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding UserName}" Width="130" MinWidth="130" MaxWidth="150">
<DataGridTextColumn.Header>
<StackPanel>
<TextBox BorderBrush="Black" BorderThickness="1" Margin="1" Name="tbUser" Width="117" MinWidth="117" MaxWidth="147"/>
<TextBlock Text="User Name" Margin="1" FontWeight="DemiBold"
TextWrapping="Wrap" TextAlignment="Left"/>
</StackPanel>
</DataGridTextColumn.Header>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
存在绑定错误Binding="{Binding User Name}"
。你的意思是Binding="{Binding UserName}"
(没有空格)?