HandyOrg / HandyOrg/HandyControl
hc:TabItem的DataTemplate 中数据绑定的Bug
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
hc:TabItem的DataTemplate 绑定的数据的表现形式是OneTime,无论Binding的Mode设置成什么值
以下是完整代码
<hc:TabControl.Template> <ControlTemplate TargetType="{x:Type hc:TabControl}"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal"> <hc:TabPanel Margin="0" IsItemsHost="True" /> <Button Width="35" Height="30" VerticalAlignment="Center" Background="Transparent" BorderThickness="0" Click="AddTabButton_Click"> <Button.Content> <Path Width="15" Height="15" Data="{StaticResource AddIcon}" Stretch="Uniform" Stroke="Black" /> </Button.Content> <Button.Style> <Style TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ContentPresenter x:Name="contentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="FloralWhite" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="White" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Button.Style> </Button> </StackPanel> <ContentPresenter Grid.Row="1" ContentSource="SelectedContent" /> </Grid> </ControlTemplate> </hc:TabControl.Template> <hc:TabControl.ItemTemplate> <DataTemplate> <TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Title, Mode=TwoWay}" /> </DataTemplate> </hc:TabControl.ItemTemplate> <hc:TabControl.ContentTemplate> <DataTemplate> <localControl:ExcelConfigControl Margin="10" ConfigData="{Binding}" /> </DataTemplate> </hc:TabControl.ContentTemplate>
Steps to reproduce the bug
<hc:TabControl.ItemTemplate> <DataTemplate> <TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Title, Mode=TwoWay}" /> </DataTemplate> </hc:TabControl.ItemTemplate>
这段代码 Text的值绑定到Title,无论Mode设置为什么值,这个绑定只生效了一次,后续修改Title的值时Text无法同步变化
且用户在TextBox中输入值时 Title的实际值跟着改变了,但是TextBox的Text依然没有变化,而且输入一次后整个TextBox卡死,无法再次输入
Expected behavior
No response
Screenshots
No response
NuGet package version
None
IDE
No response
Framework type
No response
Windows version
No response
Additional context
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided hc:TabControl.ItemTemplate and DataTemplate reproduction, focusing on the TextBox binding to Title and the related hc:TabControl template. Reproduce the reported one-time update, failed refresh, and post-input freeze, then verify that binding modes behave consistently and the TextBox remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100