wpf中textbox的Text属性因为Style的绑定,导致输入的数值始终是原来的数值,是怎么回事
xaml:<projectInfo:HistoryTextBoxGrid.Row="1"Grid.Column="1"Margin="2"VerticalAlignmen...
xaml:
<projectInfo:HistoryTextBox Grid.Row="1" Grid.Column="1"
Margin="2" VerticalAlignment="Center" x:Name="heightCtrl"
Text="{Binding Height, Converter={StaticResource ResourceKey=DoubleLengthConverter}, UpdateSourceTrigger=LostFocus}"
Style="{StaticResource CanDropDownTextBox}"
HistoryItemsSource="{x:Static control:CtpEnumHelper.LamHeightStrings}">
</projectInfo:HistoryTextBox>
<Style TargetType="{x:Type loc:HistoryTextBox}" x:Key="CanDropDownTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="loc:HistoryTextBox">
<Border>
<ComboBox IsEditable="True"
Text="{TemplateBinding Text}"
ItemsSource="{TemplateBinding HistoryItemsSource}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class HistoryTextBox : TextBox
{
//public void AddCurrTextToSource()
//{
// HistoryItemsSource.Add(base.Text);
//}
//HistoryItemsSource.
#region HistoryItemsSource DependencyProperty
public static readonly DependencyProperty HistoryItemsSourceProperty =
DependencyProperty.Register("HistoryItemsSource",typeof(object),typeof(HistoryTextBox),
new FrameworkPropertyMetadata()
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
//DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
});
public IList<string> HistoryItemsSource
{
get { return GetValue(HistoryTextBox.HistoryItemsSourceProperty) as IList<string>; }
set { SetValue(HistoryTextBox.HistoryItemsSourceProperty, value); }
}
#endregion
} 展开
<projectInfo:HistoryTextBox Grid.Row="1" Grid.Column="1"
Margin="2" VerticalAlignment="Center" x:Name="heightCtrl"
Text="{Binding Height, Converter={StaticResource ResourceKey=DoubleLengthConverter}, UpdateSourceTrigger=LostFocus}"
Style="{StaticResource CanDropDownTextBox}"
HistoryItemsSource="{x:Static control:CtpEnumHelper.LamHeightStrings}">
</projectInfo:HistoryTextBox>
<Style TargetType="{x:Type loc:HistoryTextBox}" x:Key="CanDropDownTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="loc:HistoryTextBox">
<Border>
<ComboBox IsEditable="True"
Text="{TemplateBinding Text}"
ItemsSource="{TemplateBinding HistoryItemsSource}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class HistoryTextBox : TextBox
{
//public void AddCurrTextToSource()
//{
// HistoryItemsSource.Add(base.Text);
//}
//HistoryItemsSource.
#region HistoryItemsSource DependencyProperty
public static readonly DependencyProperty HistoryItemsSourceProperty =
DependencyProperty.Register("HistoryItemsSource",typeof(object),typeof(HistoryTextBox),
new FrameworkPropertyMetadata()
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
//DefaultUpdateSourceTrigger = UpdateSourceTrigger.LostFocus
});
public IList<string> HistoryItemsSource
{
get { return GetValue(HistoryTextBox.HistoryItemsSourceProperty) as IList<string>; }
set { SetValue(HistoryTextBox.HistoryItemsSourceProperty, value); }
}
#endregion
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询