C# 如何在Windows Phone中创建带下划线的输入文本字段?
制作文本框(看起来像带下划线的输入文本字段)最简单和正确的方法是什么?您可以在信息中心的屏幕顶部和诺基亚交通工具中看到我所说的示例 我应该使用什么技术来实现它C# 如何在Windows Phone中创建带下划线的输入文本字段?,c#,silverlight,windows-phone-7,xaml,textbox,C#,Silverlight,Windows Phone 7,Xaml,Textbox,制作文本框(看起来像带下划线的输入文本字段)最简单和正确的方法是什么?您可以在信息中心的屏幕顶部和诺基亚交通工具中看到我所说的示例 我应该使用什么技术来实现它 覆盖文本框的模板以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness=“0 0 0 1”覆盖文本框的模板以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness的边框=“0 0 1”要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始 <Border
覆盖文本框的
模板
以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness=“0 0 0 1”
覆盖文本框的模板
以无背景或边框,然后在标签和文本框周围放置一个带有BorderThickness的边框=“0 0 1”
要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始
<Border BorderBrush="White" BorderThickness="0,0,0,2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="To:" Style="{StaticResource PhoneTextTitle2Style}" Margin="12,5" VerticalAlignment="Bottom"/>
<TextBox Grid.Column="1" Background="Transparent" BorderThickness="0" Foreground="{StaticResource PhoneSubtleBrush}" Text="This is a test"
VerticalAlignment="Bottom" />
</Grid>
</Border>
要模拟这些页面,您需要在边框中包装一个文本块和文本框。这应该可以让您开始
<Border BorderBrush="White" BorderThickness="0,0,0,2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="To:" Style="{StaticResource PhoneTextTitle2Style}" Margin="12,5" VerticalAlignment="Bottom"/>
<TextBox Grid.Column="1" Background="Transparent" BorderThickness="0" Foreground="{StaticResource PhoneSubtleBrush}" Text="This is a test"
VerticalAlignment="Bottom" />
</Grid>
</Border>
这可能是一种简单的方法:
- 首先,将文本框和边框的默认背景设置为透明
- 然后,您可以使用Shawn Kendrot的答案获得下划线(因为您需要在文本框中添加标签)
- 最后,要使聚焦文本框背景透明,必须遵循以下步骤
namespace Test
{
public partial class CustomTextbox : UserControl
{
public readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(CustomTextbox), null);
public readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CustomTextbox), null);
/// <summary>
/// Get/set label
/// </summary>
public string Label
{
get
{
return (string)GetValue(LabelProperty);
}
set
{
SetValue(LabelProperty, value);
}
}
/// <summary>
/// Get/set text property
/// </summary>
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
public CustomTextbox()
{
InitializeComponent();
DataContext = this;
}
}
}
名称空间测试
{
公共部分类CustomTextbox:UserControl
{
public readonly dependencProperty LabelProperty=dependencProperty.Register(“标签”、typeof(字符串)、typeof(自定义文本框)、null);
public readonly dependencProperty TextProperty=dependencProperty.Register(“Text”、typeof(string)、typeof(CustomTextbox)、null);
///
///获取/设置标签
///
公共字符串标签
{
得到
{
返回(字符串)GetValue(LabelProperty);
}
设置
{
SetValue(LabelProperty,value);
}
}
///
///获取/设置文本属性
///
公共字符串文本
{
得到
{
返回(字符串)GetValue(TextProperty);
}
设置
{
设置值(TextProperty,value);
}
}
公共自定义文本框()
{
初始化组件();
DataContext=this;
}
}
}
XAML:
崩溃
看得见的
崩溃
看得见的
使用:
<local:CustomTextbox Label="label:" Text="text"></local:CustomTextbox>